熱點推薦:
您现在的位置: 電腦知識網 >> 編程 >> Java編程 >> Java開源技術 >> 正文

Ant實戰之Jar文件數字簽名的制作

2022-06-13   來源: Java開源技術 

  buildproperties
  ==================================
  #public info
  
  module = test
  
  JAVA_HOME = C:\\jsdk_
  
  keystore = Yoinnstore
  # 別名
  alias = Yoinn
  # keystore密碼
  storepass = password
  # 主密碼
  keypass = password
  
  # 證書文件名
  cerfile = NeuLioncer
  
  # dname info
  # dname {CN= OU= O= L= ST= C=}
  # 名字與姓氏
  dnameCN = name
  # 組織單位名稱
  dnameOU = organizationUnitName
  # 組織名稱
  dnameO = organizationName
  # 所在的城市或區域名稱
  dnameL = DL
  # 所在的州或省份名稱
  dnameST = LN
  # 該單位的兩字母國家代碼
  dnameC = CN
  
  # about keytool
  keytool = keytoolexe
  keytoolhome = ${JAVA_HOME}/bin
  
  # about jarsigner
  jarsigner = jarsignerexe
  jarsignerhome = ${JAVA_HOME}/bin
  
  
  
  buildxml
  ================================
  <! Copyright (c) by Yoinn All Rights Reserved >
  <project name=JarSignerBuilder default=jarsigner basedir=>
  
   <! set global properties for this build >
   <property file=buildproperties />
   <property name=dist value=/dist />
  
   <property name=deploydir value=${basedir} />
  
   <! ********************************************************* >
  
   <! dname {CN= OU= O= L= ST= C=} ?>
  
   <!名字與姓氏>
   <property name=commonName value=${dnameCN} />
   <! 組織單位名稱 >
   <property name=organizationUnit value=${dnameOU} />
   <! 組織名稱 >
   <property name=organizationName value=${dnameO} />
   <! 所在的城市或區域名稱 >
   <property name=localityName value=${dnameL} />
   <! 所在的州或省份名稱 >
   <property name=stateName value=${dnameST} />
   <! 該單位的兩字母國家代碼 >
   <property name=country value=${dnameC} />
  
   <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=${deploydir} executable=${keytoolhome}/${keytool} os=Windows >
    <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=${deploydir} executable=${keytoolhome}/${keytool} os=Windows >
    <arg line=export />
    <arg line=keystore ${keystore} />
    <arg line=storepass ${storepass} />
    <arg line=alias ${alias} />
    <arg line=file ${cerfile} />
   </exec>
   <echo message=keytooldone />
   </target>
  
   <target name=jarsigner depends=keytool>
   <! Sign the jar >
   <echo message=jarsigner />
   <exec dir=${deploydir} executable=${jarsignerhome}/${jarsigner} os=Windows >
    <arg line=keystore ${keystore} />
    <arg line=storepass ${storepass} />
    <arg line=${module}jar />
    <arg line=${alias} />
   </exec>
      <echo message=jarsignerdone />   
   <delete file=${keystore} />
   <delete file=${cerfile} />
   <delete dir=${dist} />
   </target>
  
   <target name=undeploy>
   <delete file=${keystore} />
   <delete file=${cerfile} />
   </target>
  
  </project>

From:http://tw.wingwit.com/Article/program/Java/ky/201311/28454.html
    推薦文章
    Copyright © 2005-2022 電腦知識網 Computer Knowledge   All rights reserved.