天天看点

使用Netbeans 6.7打包第三方jar

1. 正常打包

在项目上右键,然后选择【Build】即可.

使用Netbeans 6.7打包第三方jar

打包完成后,会在项目的主目录下,生成一个[dist]文件夹。可以看到所有的第三方包都被放到了lib目录下,而不是形成单个的jar包

使用Netbeans 6.7打包第三方jar

2. 打包第三方jar

在NetBeans界面的左上方,切换到【Files】标签。打开项目目录下的build.xml文件。

使用Netbeans 6.7打包第三方jar

在build.xml的最后一行</project>的前面,加入以下代码。其中,value=”ClientMain”可以改成其他名字。比如你想生成abc.jar,那么改成value=”abc”就可以了。注意!!! Netbeans 6.9.1不允许改生成的名字,因此最后生成的temp_final.jar即为所求,生成后自行改名即可!而生成的MarsRoverViewer.jar!!!!

<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="ClientMain"/>
        <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>
           

改完build.xml后保存,在该文件上右键,依次选择【Run Target】【Other Targets】【package-for-store】

使用Netbeans 6.7打包第三方jar

等待一会儿运行完之后,可以在项目主目录下发现一个[store]文件夹,里面就是打包好的一个单一的jar包.

继续阅读