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>
文章来源于领测软件测试网 https://www.ltesting.net/
版权所有(C) 2003-2010 TestAge(领测软件测试网)|领测国际科技(北京)有限公司|软件测试工程师培训网 All Rights Reserved
北京市海淀区中关村南大街9号北京理工科技大厦1402室 京ICP备10010545号-5
技术支持和业务联系:info@testage.com.cn 电话:010-51297073