如果找到了对您有用的资料,烦请点击右手边的Google广告支持我继续共享知识,谢谢! http://dengpeng.spaces.live.com/

2009年8月17日星期一

Use NetBeans IDE 6.7 to Combine JAR Files Into a Single JAR File

This article is digested from http://java.sun.com/developer/technicalArticles/java_warehouse/single_jar/

1. Create Mars Rover Viewer project in Samples folder in NetBeans

2. Switch to Files tab, and open build.xml which is ANT script

3. Edit the file, add following text at the bottom of build.xml and before </project> tag

<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>



4. Note, this line above



<property name="store.jar.name" value="MarsRoverViewer"/>



The "MarsRoverViewer" is the name of the compiled single jar file you finally get, change it if you want



5. When you done your coding, right click on the build.xml—>Run Target—>Other Targets—>package-for-store



6. a folder called Store should appear in your project folder and the MarsRoverViewer.jar should sit in there



7. double click it and run!



For more detail, please go to http://java.sun.com/developer/technicalArticles/java_warehouse/single_jar/