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>
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.
In order to compile the project into an executable jar, please run Maven with mvn clean package command.
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.
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>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With