build-v2.xml
<project name="myviewer" default="sign" xmlns:comp="antlib:org.apache.ant.compress"> <!-- Directories for the src, jarfiles and compiled classfiles --> <property name="srcdir" value="src"/> <property name="libdir" value="lib"/> <property name="destdir" value="build"/> <!-- The Jar file we're trying to create --> <property name="jar" value="myviewer.jar"/> <!-- The keystore path, alias and password (for signing the Jar) --> <property name="ks.path" value="keystore.jks"/> <property name="ks.alias" value="myalias"/> <property name="ks.password" value="password"/> <property name="bfopdf.jar" value="${libdir}/bfopdf.jar"/> <property name="bfopdf-cmap.jar" value="${libdir}/bfopdf-cmap.jar"/> <property name="bfopdf-stamp.jar" value="${libdir}/bfopdf-stamp.jar"/> <property name="bfopdf-qrcode.jar" value="${libdir}/bfopdf-qrcode.jar"/> <property name="bfopdf-license.jar" value="${libdir}/bfopdf-license.jar"/> <property name="servicedir" value="META-INF/services" /> <property name="servicefile" value="org.faceless.pdf2.viewer2.ViewerFeature" /> <property name="build.sysclasspath" value="ignore"/> <path id="buildclasspath"> <pathelement location="${bfopdf.jar}"/> <!-- These next two files are part of your JRE - they're required to rebuild the main part of the viewer, but aren't required if you're just adding your own features --> <pathelement location="${java.home}/lib/plugin.jar"/> <pathelement location="${java.home}/lib/javaws.jar"/> </path> <!-- - Clean - do the compile and create the unsigned Jar --> <target name="clean"> <delete dir="${destdir}"/> <delete file="${jar}"/> <delete file="${jar}.pack.gz"/> </target> <!-- - Build - do the compile and create the unsigned Jar - We target Java 1.5 with our viewer, if you don't need - to remove the "source=1.5" attribute from <javac> --> <target name="build"> <mkdir dir="${destdir}/${servicedir}" /> <javac source="1.5" encoding="utf-8" srcdir="${srcdir}" destdir="${destdir}" classpathref="buildclasspath" /> <copy todir="${destdir}"> <fileset dir="${srcdir}" includes="**/resources/**" /> </copy> <!-- - This next stage combines the service file from the existing - "bfopdf.jar" with the service file from the - src/META-INF/services path. This merges the new features from - this example with the existing ones into the finished jar. --> <concat destfile="${destdir}/${servicedir}/${servicefile}"> <zipfileset src="${bfopdf.jar}"> <include name="${servicedir}/${servicefile}"/> </zipfileset> <fileset dir="src"> <include name="${servicedir}/${servicefile}"/> </fileset> </concat> <!-- - Finally build the new Jar, combining the existing "bfopdf.jar" - with the class files we've compiled at the start of this target. - Remember to exclude the service file from the original jar - - we want to use our own replacement for that --> <jar destfile="${jar}"> <zipfileset src="${bfopdf.jar}"> <exclude name="${servicedir}/${servicefile}"/> <exclude name="META-INF/*.RSA"/> <exclude name="META-INF/*.SF"/> </zipfileset> <!-- If you have a license Jar, uncomment this line to include it <zipfileset src="${bfopdf-license.jar}" /> --> <fileset dir="build"/> </jar> </target> <!-- - Sign - digitally sign the jar and create a "pack200" compressed - version of it as well. This uses the pack200 tasks from - http://ant.apache.org/antlibs/compress/, which are today (mid-2012) - probably the best way to use pack200 from Ant. Remember to set the - keystore ks.path, ks.alias and ks.password properties at the start - of this file. --> <target name="sign" depends="build"> <comp:pack200normalize srcfile="${jar}" force="true"> <property key="pack.effort" value="9"/> </comp:pack200normalize> <signjar jar="${jar}" alias="${ks.alias}" storepass="${ks.password}" keystore="${ks.path}" /> <comp:gzip destfile="${jar}.pack.gz"> <comp:pack200 srcfile="${jar}"> <property key="pack.effort" value="9"/> </comp:pack200> </comp:gzip> <!-- - These days every Jar in the applet has to be signed with the same key, - which means you have to re-sign our already signed supplementary jars. --> <signjar jar="${bfopdf-cmap.jar}" alias="${ks.alias}" storepass="${ks.password}" keystore="${ks.path}" /> <signjar jar="${bfopdf-stamp.jar}" alias="${ks.alias}" storepass="${ks.password}" keystore="${ks.path}" /> <signjar jar="${bfopdf-qrcode.jar}" alias="${ks.alias}" storepass="${ks.password}" keystore="${ks.path}" /> </target> </project>