build.properties ==================================
#public info
module = test
JAVA_HOME = C:\\j2sdk1.4.2_04
keystore = Yoinn.store
# 别名
alias = Yoinn
# keystore密码
storepass = password
# 主密码
keypass = password
# 证书文件名
cer.file = NeuLion.cer
# dname info
# dname {CN=1, OU=1, O=1, L=1, ST=1, C=1}
# 名字与姓氏
dname.CN = name
# 组织单位名称
dname.OU = organizationUnitName
# 组织名称
dname.O = organizationName
# 所在的城市或区域名称
dname.L = DL
# 所在的州或省份名称
dname.ST = LN
# 该单位的两字母国家代码
dname.C = CN
# about keytool
keytool = keytool.exe
keytool.home = ${JAVA_HOME}/bin
# about jarsigner
jarsigner = jarsigner.exe
jarsigner.home = ${JAVA_HOME}/bin
------------------------------------------------
build.xml ================================
<!-- Copyright (c) 2004 by Yoinn. All Rights Reserved. -->
<project name="JarSignerBuilder" default="jarsigner" basedir=".">
<!-- set global properties for this build -->
<property file="build.properties" />
<property name="dist" value="./dist" />
<property name="deploy.dir" value="${basedir}" />
<!-- ********************************************************* -->
<!-- dname {CN=1, OU=1, O=1, L=1, ST=1, C=1} ?-->
<!--名字与姓氏-->
<property name="commonName" value="${dname.CN}" />
<!-- 组织单位名称 -->
<property name="organizationUnit" value="${dname.OU}" />
<!-- 组织名称 -->
<property name="organizationName" value="${dname.O}" />
<!-- 所在的城市或区域名称 -->
<property name="localityName" value="${dname.L}" />
<!-- 所在的州或省份名称 -->
<property name="stateName" value="${dname.ST}" />
<!-- 该单位的两字母国家代码 -->
<property name="country" value="${dname.C}" />
<property name="dname" value="CN=${commonName},OU=${organizationUnit},O=${organizationName},L=${localityName},ST=${stateName},C=${country}" />
<!-- ********************************************************* -->
<target name="init">
<mkdir dir="${dist}" />
</target>
<target name="keytool" depends="undeploy">
<echo message="keytool..." />
<echo message="dname = { ${dname} }" />
<exec dir="${deploy.dir}" executable="${keytool.home}/${keytool}" os="Windows 2000">
<arg line="-genkey" />
<arg line="-dname ${dname}" />
<arg line="-keystore ${keystore}" />
<arg line="-alias ${alias}" />
<arg line="-storepass ${storepass}" />
<arg line="-keypass ${keypass}" />
</exec>
<exec dir="${deploy.dir}" executable="${keytool.home}/${keytool}" os="Windows 2000">
<arg line="-export" />
<arg line="-keystore ${keystore}" />
<arg line="-storepass ${storepass}" />
<arg line="-alias ${alias}" />
<arg line="-file ${cer.file}" />
</exec>
<echo message="keytool...done." />
</target>
<target name="jarsigner" depends="keytool">
<!-- Sign the jar -->
<echo message="jarsigner..." />
<exec dir="${deploy.dir}" executable="${jarsigner.home}/${jarsigner}" os="Windows 2000">
<arg line="-keystore ${keystore}" />
<arg line="-storepass ${storepass}" />
<arg line="${module}.jar" />
<arg line="${alias}" />
</exec>
<echo message="jarsigner...done." />
<delete file="${keystore}" />
<delete file="${cer.file}" />
<delete dir="${dist}" />
</target>
<target name="undeploy">
<delete file="${keystore}" />
<delete file="${cer.file}" />
</target>
</project>
查看本文来源