How to change permission of jar packaged by maven? I am using maven assembly plugin

DaBears picture DaBears · Nov 12, 2013 · Viewed 8.2k times · Source

I am using maven assembly plugin to package a jar with all dependencies. But the jar file is not executable. How can I change the permission of the jar?

-rw-r--r--  1 e17490  ADPROD\Domain Users  12072889 Nov 12 14:16 com-foo-bar.jar

Pom.xml

<plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-assembly-plugin</artifactId>
        <configuration>
          <descriptorRefs>
            <descriptorRef>jar-with-dependencies</descriptorRef>
          </descriptorRefs>
          <archive>
            <manifest>
              <mainClass>foo.Main</mainClass>
            </manifest>
          </archive>
        </configuration>
        <executions>
          <execution>
            <phase>package</phase>
            <goals>
              <goal>single</goal>
            </goals>
          </execution>
        </executions>        
      </plugin>

Answer

Jigar Joshi picture Jigar Joshi · Nov 12, 2013

Use maven:exec plugin to execute chmod

for example

<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>exec-maven-plugin</artifactId>
    <version>${org.codehaus.mojo.version}</version>
    <executions>
       <execution>
            <id>script-chmod</id>
            <phase>install</phase>
            <goals>
                <goal>exec</goal>
            </goals>
            <configuration>
                <executable>chmod</executable>
                <arguments>
                    <argument>+x</argument>
                    <argument>your-assembled-jar.jar</argument>
                </arguments>
            </configuration>
        </execution>
    </executions>
</plugin>