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
Asked
Active
Viewed 382 times
0
-
Do you want to create only one jar which should contain all the classes from your application and third party libraries ? – Sambit May 27 '19 at 08:37
-
Yes but i don't want to have the libraries unpacked in the .class files. – Lorenzo May 27 '19 at 08:38
-
1Is it possible to tell why you need jars inside the jar and not class – Vysakhan Kasthuri May 27 '19 at 08: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 – Lorenzo May 27 '19 at 08:54
-
Duplicate of https://stackoverflow.com/questions/11758594/how-do-i-put-all-required-jar-files-in-a-library-folder-inside-the-final-jar-fil?rq=1 ? – Thilo May 27 '19 at 08:54
-
No because in that question they want to put the jar library files in a directory outside the final jar so its different. I need them to be inside the final jar. – Lorenzo May 27 '19 at 08:56
-
one-jar should really be the right solution, see https://www.mkyong.com/maven/maven-create-a-fat-jar-file-one-jar-example/ if not, can you explain why? – luca.vercelli May 27 '19 at 09:35
2 Answers
0
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>

Hasitha Jayawardana
- 2,326
- 4
- 18
- 36
-
-
-
I know it will create fat jar, but does that fat jar contain other jar files ? – Sambit May 27 '19 at 11:49
-
It contains all the dependencies. (Other jars) Binds all dependencies to the jar file. – Hasitha Jayawardana May 27 '19 at 11:54
0
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

Naitik Soni
- 700
- 8
- 16