How to set up a Maven build for a Java project with external dependencies?

I am trying to create an automated build solution using maven. My vision is to have a Maven assembly that creates a JAR file from my project, and then simply copy all the dependencies as a JAR into some kind of subdirectory in the target folder.

I don’t want to use Shade or Assembly (so I don’t want to extract the contents of other JARs and include it in one “super-JAR”, because the project is more complex and it breaks when I include all the JARs in one file).

How can I make such a POM assembly?

+4
source share
3 answers

I do not see any problem here. Just create maven pom.xml with <packaging>jar</packaging> By default, it does not have to package all dependent libraries in your jar.

 <plugin> <artifactId>maven-dependency-plugin</artifactId> <executions> <execution> <phase>install</phase> <goals> <goal>copy-dependencies</goal> </goals> <configuration> <outputDirectory>${project.build.directory}/lib</outputDirectory> </configuration> </execution> </executions> </plugin> 
+7
source

Related to your last comment, use this plugin to add the main class to the manifest:

  <plugin> <!-- Build an executable JAR --> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-jar-plugin</artifactId> <configuration> <archive> <manifest> <addClasspath>true</addClasspath> <classpathPrefix>lib/</classpathPrefix> <mainClass>com.test.YourMainClass</mainClass> </manifest> </archive> </configuration> </plugin> 
+2
source

You can use the maven-assembly-plugin to create a .zip file from several other files in your directory. I used this method to create distribution zip files for the project. There are several examples available in the maven-assembly-plugin assembly .

0
source

All Articles