In NetBeans's Java project, the configured external reference jar package is copied to the Lib directory of the Dist directory by default. If you need to publish, you need to copy the jar and LIB directories generated by the Dist directory to publish, inconvenient.
There are many ways to synthesize all the required jars into one, commonly known as fat jar.
The easier way is to modify the Build.xml file
Note that the default Build.xml contains some comments, with one line:
-post-jar:called after Jar building is called after Jar compilation is complete
So at the end of the project node in Build.xml, add a little bit of content:
<target name= "-post-jar" >
<jar destfile= "./dist/final synthesized Fat_jar package. jar >
<zipfileset src= "./dist/lib/-dependent third-party package 1.jar"/>
<zipfileset src= "./dist/lib/-dependent third-party package 2.jar"/>
<!--<zipfileset src= "${reference. Subproject.jar} "/> If you rely on other project, join here--
<!--Include The main project Dist Jar...standard NB var-->
<zipfileset src= "${dist.jar}"/>
</jar>
</target>
Then, using the Build,clean and build function normally, the composite fat jar package is generated under the Dist directory.
However, there is a problem with the jar package that is generated directly:
When executed with Java-jar Xxx.jar, it is reported that:
No main manifest attribute, in Xxx.jar
The manifest information was lost because of the jar package.
Workaround:
Add some content: Under <zipfileset src= "${dist.jar}"/> This line
<manifest >
<attribute name= "main-class" value= "xxx. Xxx "/>
</manifest>
where xxx. XXX can copy the Main-class value from the manifest in the native JAR file.
Clean and Build again, all set.
NetBeans will make all the jar packages into one, commonly known as fat jar