Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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>
like image 529
DaBears Avatar asked Nov 12 '13 20:11

DaBears


People also ask

What is the use of Maven Assembly plugin?

The Assembly Plugin for Maven enables developers to combine project output into a single distributable archive that also contains dependencies, modules, site documentation, and other files. Your project can easily build distribution "assemblies" using one of the prefabricated assembly descriptors.

How do I package a Maven project into a jar?

In order to compile the project into an executable jar, please run Maven with mvn clean package command.

What is Maven Jar plugin?

Maven Jar plugin is responsible for configuring where the project's main class is so it can add it to the Jar's manifest file. If you do not include this plugin when you try to run the jar file this error will appear : Exception in thread "main" java.lang.NoClassDefFoundError.


1 Answers

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>
like image 147
jmj Avatar answered Oct 14 '22 22:10

jmj