I need a configuration for Maven where all the libraries inside the project are in the final jar in the jar format... So i need to have jars inside the final jar. For that i can only use maven. I already tried without success with plugins like one-jar. Thanks
-
Do you want to create only one jar which should contain all the classes from your application and third party libraries ?– SambitMay 27, 2019 at 8:37
-
Yes but i don't want to have the libraries unpacked in the .class files.– LorenzoMay 27, 2019 at 8:38
-
1Is it possible to tell why you need jars inside the jar and not class– Vysakhan KasthuriMay 27, 2019 at 8:49
-
Because the agency i work for use Serena to deploy the programs and when Serena explode(extract) the jar file in a directory i need to have in this directory the jar files and not the .class– LorenzoMay 27, 2019 at 8:54
-
Duplicate of stackoverflow.com/questions/11758594/… ?– ThiloMay 27, 2019 at 8:54
2 Answers
To make a fat jar
that includes all you jar
files, add the following code to your pom.xml
. When you clean and build
the project this will automatically make a fat jar
file. You need to give your main class
inside <mainClass>
tag. That's it.
<project>
<build>
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<mainClass>your.main.class</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
<executions>
<execution>
<id>final-jar-with-dependencies</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
-
-
-
I know it will create fat jar, but does that fat jar contain other jar files ?– SambitMay 27, 2019 at 11:49
-
It contains all the dependencies. (Other jars) Binds all dependencies to the jar file. May 27, 2019 at 11:54
Not sure for nested jar because I haven't tried yet.
But I have created .jar file with all project dependencies(specified in pom file)
Try following mvn command in terminal...
mvn org.apache.maven.plugins:maven-assembly-plugin:2.6:assembly -DdescriptorId=jar-with-dependencies package