Read Write permission to a jar file and all the file recursively in it

(Rahul Verma) #1

Please help me on this.

I am trying to give read write permission to all the files inside the jar file getting created by gradle script but its only give read-write permission to Jar file and not inside it…

jar {

from “$buildDir/libs/dsapGateway.ear”

ant.chmod(dir: “$buildDir/libs/”, perm: “0755”, includes: “**/*”)


task changePermission(type : Copy) << {

from “$buildDir/libs/”


gradle jar changePermission.

(Benjamin Muschko) #2

I don’t fully understand what you want to apply the file permissions to and what should be bundled into your JAR file. Are you saying everything from ‘$buildDir/libs’ should be included and get the permission 0755? If yes, you might want to try this:

jar {
    from("$buildDir/libs") {
        fileMode = 0755

(Rahul Verma) #3

Thanks for the reply but i actually need every file inside the jar file also to have chmod 755 permission. The above command only give permission to jar file but once you extract the jar file inside it is not having 755 permission.

This is required because one of our server is extracting the jar file and then recursively all file inside it.

Anyone please help on recursive logic…

(Benjamin Muschko) #4

If you want to extract each file of the EAR and bundle it with JAR file, you’ll need to use the method ‘zipTree’. I am not sure if that’s what you want as you didn’t describe that in your original question. Can you please rephrase what exactly you are trying to achieve?

(Rahul Verma) #5

sure, i have a jar file which has ear file and several other files inside it. I need that jar file and all other files inside it to be having permission 755 ( it should be going on in recursive manner for ex, a jar file has folder TEST inside it and TEST has 10 folder inside it which has many files…everything file , folder, war and ear form 1 jar only…All of them should also have permission)… Now my above code is only converting EAR and JAR to 755 not any file, war or folder inside ear to be 755

(Benjamin Muschko) #6

You can use Ant file patterns to apply the ‘fileMode’ recursively. Have a look at the doc <a/ href=“”>“Working with files”.