How to create a Netbeans style jar with all the dependencies in the lib folder?

As this question says, how to pack a Netbeans Maven project exactly the way your Netbeans native project is packaged:

  • All dependencies in a separate lib folder
  • The main project container with a manifest, which includes the lib folder on it classpath
+4
source share
1 answer

In the pom.xml file ...

1) Add this code to your project-> node properties. This will define your main class in a central location for use in many plugins.

<properties> <mainClass>project.Main.class</mainClass> </properties> 

2) Add this code to your project-> build-> plugins node. It will collect all your jar dependencies in the lib folder and compile your main jar class with the corresponding classpath link:

  <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> <plugin> <artifactId>maven-jar-plugin</artifactId> <configuration> <archive> <manifest> <addClasspath>true</addClasspath> <classpathPrefix>lib/</classpathPrefix> <mainClass>${mainClass}</mainClass> </manifest> </archive> </configuration> </plugin> 
+18
source

Source: https://habr.com/ru/post/1491426/


All Articles