Bagaimana jika suatu saat kita ingin membuat sebuah file jar dari program Java yang memanfaatkan (bergantung) dari external jar (biasanya di folder dist\lib)? Berikut adalah langkah-langkah untuk membuat file jar tersebut dengan Netbeans.
- Pertama-tama lakukan clean and build pada program yang ingin dibuat file jar-nya. Pada contoh ini, program SentenceSegmentation ingin dibuat file jar.
- Selanjutnya buka build.xml pada folder SentenceSegmentation.
- Hapus isi build.xml dan masukkan kode berikut pada build.xml. SentSeg.jar adalah file jar hasilnya.
<?xml version="1.0" encoding="UTF-8"?>
<project name="SentenceSegmentation" default="default" basedir=".">
<description>Builds, tests, and runs the project SentenceSegmentation.</description>
<import file="nbproject/build-impl.xml"/>
<target name="package-for-store" depends="jar">
<property name="store.jar.name" value="SentSeg"/>
<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"/>
</zip>
<delete file="${store.dir}/temp_final.jar"/>
</target>
</project>
<project name="SentenceSegmentation" default="default" basedir=".">
<description>Builds, tests, and runs the project SentenceSegmentation.</description>
<import file="nbproject/build-impl.xml"/>
<target name="package-for-store" depends="jar">
<property name="store.jar.name" value="SentSeg"/>
<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"/>
</zip>
<delete file="${store.dir}/temp_final.jar"/>
</target>
</project>
4. Pada build.xml, klik kanan, pilih "Run Target" > "Other Targets" > "package-for-store"
5. SentSeg.jar berhasil dibuat di SentenceSegmentation\store\SentSeg.jar.
Versi Java 1.8.0
Netbeans IDE 8.0.2
Windows 8
Referensi:
http://arunasujith.blogspot.co.id/2011/08/how-to-build-fat-jar-using-netbeans.html
Comments
Post a Comment