Original post address: http://www.icycandy.com/blog/use-netbeans-to-combine-jar-files-into-a-single-jar-file1. Normal Packaging
Right-click the project and select build.
After packaging, a [Dist] folder is generated under the main directory of the project. We can see that all third-party packages are placed under the lib directory, instead of forming a single jar package.
2. Package third-party jar
This method was found after searching for a long time, from the sun official website. The original Article is here.
In the upper-left corner of the netbeans interface, switch to the files tab. Open the build. xml file in the project directory.
Last line of build. xml
Before, add the following code. Here, the value = "marsroverviewer" in the row 7th can be changed to another name. For example, if you want to generate ABC. jar, you can change it to value = "ABC.
123456789101112131415161718192021222324252627282930313233343536 |
<target name="package-for-store" depends="jar"> <!-- Change the value of this property to be the name of your JAR, minus the .jar extension. It should not have spaces. <property name="store.jar.name" value="MyJarName"/> --> <property name="store.jar.name" value="MarsRoverViewer"/> <!-- don't edit below this line --> <property name="store.dir" value="store"/> <property name="store.jar" value="${store.dir}/${store.jar.name}.jar"/> <echo message="Packaging ${application.title} into a single JAR at ${store.jar}"/> <delete dir="${store.dir}"/> <mkdir dir="${store.dir}"/> <jar destfile="${store.dir}/temp_final.jar" filesetmanifest="skip"> <zipgroupfileset dir="dist" includes="*.jar"/> <zipgroupfileset dir="dist/lib" includes="*.jar"/> <manifest> <attribute name="Main-Class" value="${main.class}"/> </manifest> </jar> <zip destfile="${store.jar}"> <zipfileset src="${store.dir}/temp_final.jar" excludes="META-INF/*.SF, META-INF/*.DSA, META-INF/*.RSA"/> </zip> <delete file="${store.dir}/temp_final.jar"/> </target> |
After you change the build. xml file, right-click the file and choose run target> other targets> package-for-store]
After a while, you can find a [store] folder in the main directory of the project, which is a single jar package.
3. Package A third-party jar using the command line
The command line packaging method should be the most flexible and powerful, but so far I have not.