Issue
I have a little utility program, in Java, written with Netbeans as a "Maven project" (the little icon on the project has the stylized "m" over it). I want to package this utility, and the libraries on which it depends, as a jar file; I want the jar file to include the necessary runtime libraries so I don't have to package those up separately.
The Netbeans instructions say that, when I run build, I'll have 'dist' and 'lib' directories created under the project directory, and that (since I've set the main class in the project properties), I'll have it specified in my manifest file. None of this has happened; the project builds and runs fine under IDE, but it creates a jar that contains only the utilities specific classes, no library classes, the manifest doesn't have my main class written to it, and the library classes are not in the jar.
Is it because this is a maven project instead of a default Netbeans Java project? How can I get this done with a Maven project in Netbeans?
--
After adding the maven-assembly-plugin as suggested, the console output from a "clean and build" looks like this:
cd C:\Users\rcook\Documents\NetBeansProjects\OlbUserLoad; "JAVA_HOME=C:\\Program Files\\Java\\jdk1.7.0_07" M2_HOME=C:\\devTools\\apache-maven cmd /c "\"\"C:\\devTools\\apache-maven\\bin\\mvn.bat\" -DskipTests=true
-Dmaven.ext.class.path=\"C:\\Program Files\\NetBeans 8.1\\java\\maven-nblib\\netbeans-eventspy.jar\" -Dfile.encoding=UTF-8 clean install\"" Scanning for projects...
------------------------------------------------------------------------ Building OlbUserLoad 1.0-SNAPSHOT
------------------------------------------------------------------------
--- maven-clean-plugin:2.4.1:clean (default-clean) @ OlbUserLoad --- Deleting C:\Users\rcook\Documents\NetBeansProjects\OlbUserLoad\target
--- maven-resources-plugin:2.5:resources (default-resources) @ OlbUserLoad --- [debug] execute contextualize Using 'UTF-8' encoding to copy filtered resources. Copying 1 resource Copying 0 resource
--- maven-compiler-plugin:2.0.2:compile (default-compile) @ OlbUserLoad --- Compiling 1 source file to C:\Users\rcook\Documents\NetBeansProjects\OlbUserLoad\target\classes
--- maven-resources-plugin:2.5:testResources (default-testResources) @ OlbUserLoad --- [debug] execute contextualize Using 'UTF-8' encoding to copy filtered resources. skip non existing resourceDirectory C:\Users\rcook\Documents\NetBeansProjects\OlbUserLoad\src\test\resources
--- maven-compiler-plugin:2.0.2:testCompile (default-testCompile) @ OlbUserLoad --- Nothing to compile - all classes are up to date
--- maven-surefire-plugin:2.10:test (default-test) @ OlbUserLoad --- Tests are skipped.
--- maven-jar-plugin:2.3.2:jar (default-jar) @ OlbUserLoad --- Building jar: C:\Users\rcook\Documents\NetBeansProjects\OlbUserLoad\target\OlbUserLoad-1.0-SNAPSHOT.jar
--- maven-install-plugin:2.3.1:install (default-install) @ OlbUserLoad --- Installing C:\Users\rcook\Documents\NetBeansProjects\OlbUserLoad\target\OlbUserLoad-1.0-SNAPSHOT.jar to C:\Users\rcook\.m2\repository\com\accesspoint\OlbUserLoad\1.0-SNAPSHOT\OlbUserLoad-1.0-SNAPSHOT.jar Installing C:\Users\rcook\Documents\NetBeansProjects\OlbUserLoad\pom.xml to C:\Users\rcook\.m2\repository\com\accesspoint\OlbUserLoad\1.0-SNAPSHOT\OlbUserLoad-1.0-SNAPSHOT.pom
------------------------------------------------------------------------ BUILD SUCCESS
------------------------------------------------------------------------ Total time: 2.155s Finished at: Fri Apr 22 10:15:28 EDT 2016 Final Memory: 17M/152M
------------------------------------------------------------------------
I'm hoping that helps us figure out what else is missing.
Solution
Include this plugin in your .pom file. This is to tell Maven to assemble your application with the dependencies.
After this, in Netbeans build your project and you will see the jar with dependencies.
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<archive>
<manifest>
<mainClass>Your Main Class</mainClass>
</manifest>
</archive>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
Refer to: Creating a Java Maven Project in NetBeans IDE 7.4
Answered By - lkq
Answer Checked By - Candace Johnson (JavaFixing Volunteer)