话不多说,我们先建立一个文件build.properties。这个文件是用于配置一些常用的变量的
好了,就这么简单,我们做第二步,制作一个Ant构建文件build.xml
好了,直接执行就可以了。
哦,我的目录结构是这样的
您按这个看看就了解了。;)
#public info
module = test
JAVA_HOME = D:/Java/JDK1 .6
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
module = test
JAVA_HOME = D:/Java/JDK1 .6
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
<?
xml version="1.0"
?>
<!-- Copyright (c) 2004 by Yoinn. All Rights Reserved. -->
< project name ="JarSignerBuilder" default ="main" basedir ="." >
<!-- set global properties for this build -->
< property file ="build.properties" />
< property name ="libDir" value ="WebRootWEB-INFlib" />
< property name ="deploy.dir" value ="${basedir}" />
<!-- ********************************************************* -->
<!-- 名字与姓氏 -->
< 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}" />
<!-- dname {CN=1, OU=1, O=1, L=1, ST=1, C=1} ? -->
< property name ="dname" value ="CN=${commonName},OU=${organizationUnit},O=${organizationName},L=${localityName},ST=${stateName},C=${country}" />
<!-- ********************************************************* -->
< property name ="src.dir" value ="src" />
< property name ="build.dir" value ="build" />
< property name ="classes.dir" value ="${build.dir}/classes" />
< property name ="jar.dir" value ="${build.dir}/jar" />
< property name ="jarSignerBuilder" value ="${jar.dir}/${ant.project.name}.jar" />
< property name ="main-class" value ="ZUpload" />
< target name ="clean" >
< delete dir ="${build.dir}" />
</ target >
< path id ="build.classpath" >
< fileset dir ="${libDir}" >
< include name ="**/*.jar" />
</ fileset >
</ path >
< target name ="compile" >
< mkdir dir ="${classes.dir}" />
< javac srcdir ="${src.dir}" destdir ="${classes.dir}" >
< classpath refid ="build.classpath" />
</ javac >
</ target >
< target name ="jar" depends ="compile" >
< mkdir dir ="${jar.dir}" />
< jar destfile ="${jarSignerBuilder}" basedir ="${classes.dir}" >
< manifest >
< attribute name ="Main-Class" value ="${main-class}" />
< attribute name ="Built-By" value ="Ken.xu" />
< attribute name ="Company" value ="TXKJ" />
</ manifest >
</ jar >
</ target >
< target name ="run" depends ="jar" >
< java jar ="${jar.dir}/${ant.project.name}.jar" fork ="true" />
</ target >
< target name ="clean-build" depends ="clean,jar" />
< target name ="main2" depends ="clean,run" />
<!-- 打包Jar2,无用的 -->
< target name ="jar2" >
< jar destfile ="${distDir}web.jar" basedir ="${buildDir}" >
< manifest >
< attribute name ="Built-By" value ="Ken.xu" />
< attribute name ="Company" value ="TXKJ" />
</ manifest >
< zipfileset src ="${libDir}/common.jar" />
< zipfileset src ="${libDir}/classes12.jar" />
< zipfileset src ="${libDir}/commons-collections-3.1.jar" />
< zipfileset src ="${libDir}/commons-lang-2.1.jar" />
</ jar >
< jar destfile ="${distDir}/web-src.jar" basedir ="${srcDir}" />
</ target >
< target name ="keytool" depends ="clean-build" >
< echo message ="keytool..." />
< echo message ="dname = { ${dname} }" />
< exec dir ="${deploy.dir}" executable ="${keytool.home}/${keytool}" os ="${os.name}" >
< 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 ="${os.name}" >
< 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 ="${os.name}" >
< arg line ="-keystore ${keystore}" />
< arg line ="-storepass ${storepass}" />
< arg line ="${jarSignerBuilder}" />
< arg line ="${alias}" />
</ exec >
< echo message ="jarsigner...done." />
</ target >
< target name ="main" depends ="jarsigner" >
< delete file ="${keystore}" />
< delete file ="${cer.file}" />
< delete dir ="${classes.dir}" />
</ target >
</ project >
<!-- Copyright (c) 2004 by Yoinn. All Rights Reserved. -->
< project name ="JarSignerBuilder" default ="main" basedir ="." >
<!-- set global properties for this build -->
< property file ="build.properties" />
< property name ="libDir" value ="WebRootWEB-INFlib" />
< property name ="deploy.dir" value ="${basedir}" />
<!-- ********************************************************* -->
<!-- 名字与姓氏 -->
< 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}" />
<!-- dname {CN=1, OU=1, O=1, L=1, ST=1, C=1} ? -->
< property name ="dname" value ="CN=${commonName},OU=${organizationUnit},O=${organizationName},L=${localityName},ST=${stateName},C=${country}" />
<!-- ********************************************************* -->
< property name ="src.dir" value ="src" />
< property name ="build.dir" value ="build" />
< property name ="classes.dir" value ="${build.dir}/classes" />
< property name ="jar.dir" value ="${build.dir}/jar" />
< property name ="jarSignerBuilder" value ="${jar.dir}/${ant.project.name}.jar" />
< property name ="main-class" value ="ZUpload" />
< target name ="clean" >
< delete dir ="${build.dir}" />
</ target >
< path id ="build.classpath" >
< fileset dir ="${libDir}" >
< include name ="**/*.jar" />
</ fileset >
</ path >
< target name ="compile" >
< mkdir dir ="${classes.dir}" />
< javac srcdir ="${src.dir}" destdir ="${classes.dir}" >
< classpath refid ="build.classpath" />
</ javac >
</ target >
< target name ="jar" depends ="compile" >
< mkdir dir ="${jar.dir}" />
< jar destfile ="${jarSignerBuilder}" basedir ="${classes.dir}" >
< manifest >
< attribute name ="Main-Class" value ="${main-class}" />
< attribute name ="Built-By" value ="Ken.xu" />
< attribute name ="Company" value ="TXKJ" />
</ manifest >
</ jar >
</ target >
< target name ="run" depends ="jar" >
< java jar ="${jar.dir}/${ant.project.name}.jar" fork ="true" />
</ target >
< target name ="clean-build" depends ="clean,jar" />
< target name ="main2" depends ="clean,run" />
<!-- 打包Jar2,无用的 -->
< target name ="jar2" >
< jar destfile ="${distDir}web.jar" basedir ="${buildDir}" >
< manifest >
< attribute name ="Built-By" value ="Ken.xu" />
< attribute name ="Company" value ="TXKJ" />
</ manifest >
< zipfileset src ="${libDir}/common.jar" />
< zipfileset src ="${libDir}/classes12.jar" />
< zipfileset src ="${libDir}/commons-collections-3.1.jar" />
< zipfileset src ="${libDir}/commons-lang-2.1.jar" />
</ jar >
< jar destfile ="${distDir}/web-src.jar" basedir ="${srcDir}" />
</ target >
< target name ="keytool" depends ="clean-build" >
< echo message ="keytool..." />
< echo message ="dname = { ${dname} }" />
< exec dir ="${deploy.dir}" executable ="${keytool.home}/${keytool}" os ="${os.name}" >
< 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 ="${os.name}" >
< 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 ="${os.name}" >
< arg line ="-keystore ${keystore}" />
< arg line ="-storepass ${storepass}" />
< arg line ="${jarSignerBuilder}" />
< arg line ="${alias}" />
</ exec >
< echo message ="jarsigner...done." />
</ target >
< target name ="main" depends ="jarsigner" >
< delete file ="${keystore}" />
< delete file ="${cer.file}" />
< delete dir ="${classes.dir}" />
</ target >
</ project >
好了,直接执行就可以了。
哦,我的目录结构是这样的
D:Eclipseworkspace_3.3ZUpload 的目录
build.properties build.xml [src] [WebRoot]
D:Eclipseworkspace_3.3ZUploadsrc 的目录
[apache] ZUpload.java
D:Eclipseworkspace_3.3ZUploadsrcapache est 的目录
MyTest.java
D:Eclipseworkspace_3.3ZUploadWebRoot 的目录
index.jsp [WEB-INF]
D:Eclipseworkspace_3.3ZUploadWebRootWEB-INF 的目录
[classes] [lib] web.xml
D:Eclipseworkspace_3.3ZUploadWebRootWEB-INFlib 的目录
ant.jar
build.properties build.xml [src] [WebRoot]
D:Eclipseworkspace_3.3ZUploadsrc 的目录
[apache] ZUpload.java
D:Eclipseworkspace_3.3ZUploadsrcapache est 的目录
MyTest.java
D:Eclipseworkspace_3.3ZUploadWebRoot 的目录
index.jsp [WEB-INF]
D:Eclipseworkspace_3.3ZUploadWebRootWEB-INF 的目录
[classes] [lib] web.xml
D:Eclipseworkspace_3.3ZUploadWebRootWEB-INFlib 的目录
ant.jar
您按这个看看就了解了。;)