How do I create a Netbeans style Jar with all dependencies in a lib folder?
In your pom.xml file ...
1) Add this code to your project->properties node. This will define your main class in a central place 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 into a lib folder AND compile your main class jar with the proper classpath reference:
<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>
The Coordinator
I am the protagonist in many popular Java-based business and hobby codebase box office hits. As an ambidextrous hard-partying and swinging hippie programmer, I save the world from code bugs and thaw cryogenically frozen greatness from my colleagues tortured and uncompiled source - while writing great code! Not only have I actually met Borat, I also have experience with Java, Groovy, Python, Fortran, QBasic, Bash, DOS and just about anything else required to get the job done in a multidisciplinary, undisciplined and uncouth-although-amazing software environment. My big project will be the Oz programming language. When it materializes, all other programming domains will crumble before the all-powerful, syntactically beautiful and functionally implicit Oz! I suppose I would then be the Wizard of Oz ;-)
Updated on June 05, 2022Comments
-
The Coordinator almost 2 years
As the question says, how to package a Netbeans Maven project exactly the way a Netbeans native project is packaged:
- All the dependencies in a separate lib folder
- The main project jar with a manifest that includes the lib folder on it's classpath