NetBeans will make all the jar packages into one, commonly known as fat jar

Source: Internet
Author: User
Tags netbeans

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.