转载请注明出处,原文网址:http://blog.csdn.net/m_changgong/article/details/7715274 作者:张燕广
整理磁盘发现很久之前写的Ant编译、打包及签名jar脚本,共享出来仅供参考吧(应该还有可完善之处)。
共有2个xml文件:build.xml及build-common.xml,前者调用了后者。
build.xml如下:
<?xml version="1.0" encoding="UTF-8"?> <project name="isoftRdpClient-2.0" default="standalone" basedir="."> <property name="jar.name" value="properJavaRDP"/> <property name="dist.dir" value="${basedir}/dist"/> <property name="build.dir" value="${basedir}/build"/> <property name="bin.dir" value="${basedir}/bin"/> <property name="src.dir" value="${basedir}/src"/> <property name="rpm.dir" value="${basedir}/rpm"/> <property name="build.extension" value="${basedir}/extension"/> <property name="java.log4j11.package" value="${basedir}/log4j-java1.1"/> <property name="java.getopt.package" value="${basedir}/gnu-getopt-1.0.11-java/lib"/> <property name="java.quartz.package" value="${basedir}/quartz-1.8.0"/> <property name="java.printer.package" value="${basedir}/printer"/> <property name="log4j.java11" value="log4j-java1.1"/> <property name="jar.log4j.java11" value="log4j-java1.1.jar"/> <property name="jar.gnugetopt" value="java-getopt-1.0.11.jar"/> <property name="jar.quartz" value="quartz-1.8.0.jar"/> <property name="jar.jta" value="jta-1.1.jar"/> <property name="jar.dbcp" value="commons-dbcp-1.3.jar"/> <property name="jar.pool" value="commons-pool-1.5.4.jar"/> <property name="jar.log4j12" value="log4j-1.2.14.jar"/> <property name="jar.slf4j" value="slf4j-api-1.5.10.jar"/> <property name="jar.slf4jlog" value="slf4j-log4j12-1.5.10.jar"/> <property name="jar.printer" value="os_jpedal.jar"></property> <property name="commonxml" value="${basedir}/build-common.xml"/> <property name="runclass" value="com.elusiva.rdp.RdesktopSwing"/> <!-- jar包数字签名相关属性开始--> <property name="jarName" value="JavaRDP16-1.1.jar" /> <property name="keystorePath" value="${build.dir}/keystore" /> <!-- 数字签名用的密钥信息参数 --> <property name="keystoreName" value="isoftkeystore.store" /> <property name="storepass" value="isoft123" /> <property name="keystore" location="${keystorePath}/${keystoreName}" /> <property name="keypass" value="isoft123" /> <property name="keysize" value="1024" /> <property name="alias" value="isoft" /> <property name="validity" value="365" /> <!-- jar包数字签名相关属性结束--> <!-- Load additional and personalised properties --> <property file="${basedir}/project.properties"/> <target name="init"> <ant antfile="${commonxml}" target="init-common"/> </target> <target name="build" depends="init"> <ant antfile="${commonxml}" target="build-common"/> <property file="${build.dir}/product.version"/> </target> <target name="jar" depends="build"> <property name="jar.path" value="${jar.name}-${product.version}.jar" /> <property name="jar.path.16" value="${jar.name}16-${product.version}.jar" /> <mkdir dir="${dist.dir}" /> <ant antfile="${commonxml}" target="jar-common"/> </target> <target name="dist" depends="jar"> <jar jarfile="${dist.dir}/${jar.log4j.java11}" defaultexcludes="no" excludes="META-INF/*"> <zipfileset src="${java.log4j11.package}/${jar.log4j.java11}" excludes="META-INF/*"/> </jar> <jar jarfile="${dist.dir}/${jar.gnugetopt}" defaultexcludes="no" excludes="META-INF/*"> <zipfileset src="${java.getopt.package}/${jar.gnugetopt}" excludes="META-INF/*"/> </jar> <jar jarfile="${dist.dir}/${jar.quartz}" defaultexcludes="no" excludes="META-INF/*"> <zipfileset src="${java.quartz.package}/${jar.quartz}" excludes="META-INF/*,*.java"/> <zipfileset src="${java.quartz.package}/${jar.jta}" excludes="META-INF/*,*.java"/> <zipfileset src="${java.quartz.package}/${jar.log4j12}" excludes="META-INF/*,*.java"/> <zipfileset src="${java.quartz.package}/${jar.dbcp}" excludes="META-INF/*,*.java"/> <zipfileset src="${java.quartz.package}/${jar.pool}" excludes="META-INF/*,*.java"/> <zipfileset src="${java.quartz.package}/${jar.slf4j}" excludes="META-INF/*,*.java"/> <zipfileset src="${java.quartz.package}/${jar.slf4jlog}" excludes="META-INF/*,*.java"/> <zipfileset src="${java.printer.package}/${jar.printer}" excludes="META-INF/*,*.java"/> </jar> </target> <target name="release" description="Create the extension archive" depends="standalone"> <copy file="${dist.dir}/JavaRDP16-${product.version}.jar" tofile="${build.extension}/JavaRDP16-${product.version}.jar"/> <copy file="${basedir}/extension.xml" tofile="${build.extension}/extension.xml"/> <echo>Creating the archive</echo> <zip destfile="${dist.dir}/application-seamlessjavardp.zip"> <zipfileset dir="${build.extension}" prefix="application-seamlessjavardp" includes="**/*"/> </zip> <echo>Generating checksums</echo> <checksum> <fileset dir="${dist.dir}" includes="*.zip"/> </checksum> </target> <target name="standalone" depends="init"> <uptodate targetfile="${ant.file}" property="build.changed"> <srcfiles dir="${src.dir}" includes="**/*.java"/> <srcfiles dir="${src.dir}1.5" includes="**/*.java"/> <srcfiles dir="${src.dir}1.6" includes="**/*.java"/> </uptodate> <ant antfile="${commonxml}" target="build-common-version"> <property name="java.version" value="1.5"/> <property name="java.version" value="1.6"/> </ant> <ant antfile="${commonxml}" target="generate-product-version"/> <property file="${build.dir}/product.version"/> <jar destfile="${dist.dir}/JavaRDP16-${product.version}.jar" index="yes"> <manifest> <attribute name="Built-By" value="${user.name}"/> <attribute name="Main-Class" value="${runclass}"/> </manifest> <fileset dir="${build.dir}" includes="**/*.class, **/*.properties"/> <fileset dir="${build.dir}1.6" includes="**/*.class, **/*.PNG"/> <fileset dir="${basedir}/" includes="keymaps/*"/> <!-- <zipfileset src="${java.log4j11.package}/${jar.log4j.java11}" excludes="META-INF/*"/> --> <zipfileset src="${java.getopt.package}/${jar.gnugetopt}" excludes="META-INF/*,*.java"/> <zipfileset src="${java.quartz.package}/${jar.quartz}" excludes="META-INF/*,*.java"/> <zipfileset src="${java.quartz.package}/${jar.jta}" excludes="META-INF/*,*.java"/> <zipfileset src="${java.quartz.package}/${jar.log4j12}" excludes="META-INF/*,*.java"/> <zipfileset src="${java.quartz.package}/${jar.dbcp}" excludes="META-INF/*,*.java"/> <zipfileset src="${java.quartz.package}/${jar.pool}" excludes="META-INF/*,*.java"/> <zipfileset src="${java.quartz.package}/${jar.slf4j}" excludes="META-INF/*,*.java"/> <zipfileset src="${java.quartz.package}/${jar.slf4jlog}" excludes="META-INF/*,*.java"/> <zipfileset src="${java.printer.package}/${jar.printer}" excludes="META-INF/*,*.java"/> </jar> </target> <target name="run" depends="build"> <java classname="${runclass}"> <arg value="m6.propero.int"/> <classpath> <!-- include common class files, java 1.6 class files and log4j jar --> <pathelement path="${build.dir}"/> <pathelement path="${build.dir}1.6"/> <pathelement location="${jar.log4j.java11}" /> </classpath> </java> </target> <target name="clean"> <ant antfile="${commonxml}" target="clean-common"/> <delete dir="${rpm.dir}" /> </target> <!-- 数字签名相关target --> <!-- 创建证书 --> <target name="genericKey"> <echo message="genkey..." /> <delete> <fileset dir="${keystorePath}"> <include name="${keystoreName}" /> </fileset> </delete> <genkey keystore="${keystore}" storepass="${storepass}" alias="${alias}" keypass="${keypass}" keysize="${keysize}" validity="${validity}" dname="CN=isoft i-VAPP, OU=Jakarta Division, O=Apache.org, C=ZH"> </genkey> <echo message="genkey... done" /> </target> <!-- 对JAR进行数字签名 --> <target name="signJar" depends="genericKey,standalone"> <echo message="jarsigner..." /> <echo message="${keystore}"/> <signjar keystore="${keystore}" storepass="${storepass}" jar="${jarName}" alias="${alias}"> <fileset dir="${dist.dir}"> <include name="${jarName}" /> </fileset> </signjar> <echo message="jarsigner... done." /> </target> </project>build-common.xml如下:
<?xml version="1.0" encoding="UTF-8"?> <project name="build-comm" default="init-common" basedir="."> <property file="${basedir}/project.properties"/> <!-- CLASSPATH required for build. --> <path id="build.classpath"> <fileset dir="${java.log4j11.package}" includes="${jar.log4j.java11}"/> <fileset dir="${java.getopt.package}" includes="${jar.gnugetopt}"/> <fileset dir="${java.quartz.package}" includes="${jar.quartz}"/> <fileset dir="${java.printer.package}" includes="${jar.printer}"> </fileset> </path> <target name="init-common"> <mkdir dir="${build.dir}"/> <mkdir dir="${build.dir}1.6"/> <mkdir dir="${dist.dir}" /> <mkdir dir="${keystorePath}"/> <mkdir dir="${build.dir}/keymaps"/> <mkdir dir="${bin.dir}"/> <copy todir="${build.dir}/keymaps"> <fileset dir="${basedir}/keymaps" /> </copy> </target> <target name="generate-product-version" depends="init-common"> <javac srcdir="${src.dir}" includes="**/Version.java" destdir="${build.dir}"/> <java classpath="${build.dir}" classname="com.elusiva.rdp.Version"> <arg value="${build.dir}/product.version"/> </java> </target> <target name="build-common-version"> <javac srcdir="${src.dir}:${src.dir}${java.version}" destdir="${build.dir}" classpathref="build.classpath" fork="true" target="${java.version}"> </javac> <javac srcdir="${src.dir}:${src.dir}${java.version}" destdir="${bin.dir}" classpathref="build.classpath" fork="true" target="${java.version}"> </javac> <mkdir dir="${build.dir}${java.version}/com/elusiva/rdp" /> <move todir="${build.dir}${java.version}/com/elusiva/rdp"> <fileset dir="${build.dir}/com/elusiva/rdp" includes="*_Localised.class"/> </move> <copy todir="${build.dir}/com/elusiva/rdp"> <fileset dir="" includes="*.png,*.PNG " /> </copy> </target> <target name="build-common"> <!-- Build each version of the code in turn. Note this will be replaced by an antCall element when we can be assured everyone will have Ant 1.5.2 --> <ant antfile="${commonxml}" target="build-common-version"> <property name="java.version" value="1.6"/> </ant> <ant antfile="${commonxml}" target="generate-product-version"/> <property file="${build.dir}/product.version"/> </target> <target name="jar-common"> <copy toDir="${build.dir}/keymaps" filtering="true"> <fileset dir="${basedir}/keymaps"/> </copy> <jar jarfile="${dist.dir}/${jar.path}" basedir="${build.dir}/"/> <jar jarfile="${dist.dir}/${jar.path.16}" basedir="${build.dir}1.6/"/> </target> <target name="clean-common"> <delete dir="${build.dir}" /> <delete dir="${build.dir}1.6" /> <delete dir="${build.dir}1.4" /> <delete dir="${build.dir}1.3" /> <delete dir="${build.dir}1.2" /> <delete dir="${build.dir}1.1" /> <delete dir="${dist.dir}" /> <delete dir="${bin.dir}"/> </target> </project>