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

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.

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

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…

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?

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

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