Can not set the final jar name with maven-assembly-plugin - java

This is how I configured maven-assembly-plugin
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.4</version>
<configuration>
<finalName>myapp</finalName>
<archive>
<manifest>
<mainClass>com.myapp.Main</mainClass>
</manifest>
</archive>
<!--
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
-->
</configuration>
</plugin>
and I expect the final jar file should be myapp.jar but it ends up with myapp-jar-with-dependencies.jar
Can you tell me how to configure to exclude "jar-with-dependencies" out of the final name?

You can specify the finalName property to give the jar the name you want, and specify that appendAssemblyId should be false to avoid the jar-with-dependencies suffix.
The configuration below will output a jar called test.jar
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.4</version>
<configuration>
<finalName>test</finalName>
<archive>
<manifest>
<mainClass>com.myapp.Main</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<appendAssemblyId>false</appendAssemblyId>
</configuration>
</plugin>

Related

org.apache.flink.client.program.ProgramInvocationException: The program's entry point class 'com.example.KafkaFlink' was not found in the jar file

I was getting an error ProgramInvocationException while trying upload a jar file to flink local server
Here is the pom.xml of code
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<classpathPrefix>lib/</classpathPrefix>
<mainClass>com.example.KafkaFlink</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
</plugins>
</build>

No main manifest attribute in .jar

I search in Internet many information, but I don't know what's porblem is that...
Please, check this:
Manifest:
Manifest-Version: 1.0
Main-Class: BotPolytechnic
POM:
<groupId>FPolytechnic</groupId>
<artifactId>FPolytechnic</artifactId>
<version>1.0</version>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.2</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
<archive>
<manifest>
<mainClass>BotPolytechnic</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
</plugins>
</build>
use instead the maven-jar-plugin to make the JAR executable:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<mainClass>fully.qualified.MainClass</mainClass>
</manifest>
</archive>
</configuration>
</plugin>

assembly-maven-plug not generate jar-with-dependecies ad no main manifest attribute

Hi when i run mvn package the assembly plugin generate the jar name AnonymousChat-1.0-SNAPSHOT.jar then i thought this shuld be good then i try to run this jar but i had the error "no main manifest attribute" this is the snippet of maven plugin:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>3.1.1</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
<configuration>
<archive>
<manifest>
<mainClass>com.shell.Terminal</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
</execution>
</executions>
</plugin>
I find this code that will solve the problem, if for someone can be useful I write i here.
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<archive>
<manifest>
<mainClass>com.shell.Terminal</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
</plugin>

mvn jar file : library include failed

I did mvn package and ran my file by doing java -jar target\output.jar
All the jar libraries specified in the dependency of pom.xml are not included. Do advice what's wrong below. Thanks!
Below is my pom.xml to allow jar file generation.
<plugin>
<!-- Build an executable JAR -->
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.1.0</version>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<classpathPrefix>lib/</classpathPrefix>
<mainClass>com.workspez.psg.letrikEtara.PlanetGroupLetrikEtara</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
Try and compare/complete your declaration with the ones in "Including dependencies in a jar with Maven", like adding the executions section.
Or, if this is not working, consider the maven shade plugin, whic can achieve a simlar goal.
Got it working. This was missing:
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
To the following should work:
<plugin>
<!-- Build an executable JAR -->
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.1.0</version>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<classpathPrefix>lib/</classpathPrefix>
<mainClass>com.workspez.psg.letrikEtara.PlanetGroupLetrikEtara</mainClass>
</manifest>
</archive>
</configuration>
</plugin>

Putting version information in manifest file into JAR using Maven

I am trying to find a way of putting version information in manifest file into JAR using Maven?
For WAR files I use the following in my POM.XML
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.6</version>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<addDefaultImplementationEntries>true</addDefaultImplementationEntries>
</manifest>
</archive>
</configuration>
</plugin>
and then I run "mv clean package"
How would you do this for a JAR.. Can you please give me details information on the changes and the commands... thanks
You can use maven-jar-plugin (the configuration is nearly the same as maven-war-plugin)
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.6</version>
<configuration>
<archive>
<index>true</index>
<manifest>
<addClasspath>true</addClasspath>
</manifest>
<manifestEntries>
<mode>development</mode>
<url>${project.url}</url>
<key>value</key>
</manifestEntries>
</archive>
</configuration>
...
</plugin>
Here the documentation of the plugin: https://maven.apache.org/plugins/maven-jar-plugin/examples/manifest-customization.html
And all options: http://maven.apache.org/shared/maven-archiver/index.html

Categories