爱程序网

NetBeans将java项目编译成jar包

来源: 阅读:

1.找到file选项下的build.xml。

2.添加代码到build.xml文件的</project>标志之前 。

复制如下代码:

<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="此处即你要打包成jar的文件名"/>

        -->

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

 

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

 

3. build.xml右键即可打包生成SwitchHexAndChinese.jar

  run target ---》other target-----》package -for-store

 

 

4.files---->store---->your jar

store文件夹下即你的目标jar包

 

关于爱程序网 - 联系我们 - 广告服务 - 友情链接 - 网站地图 - 版权声明 - 人才招聘 - 帮助