gpt4 book ai didi

java - 如何使用 jarsigner 签署十几个 JAR 文件?

转载 作者:行者123 更新时间:2023-11-30 04:46:07 25 4
gpt4 key购买 nike

我想使用 jarsigner 签署两打 jar 文件,只提供一次密码。

根据手册页,向 jarsigner 提供多个文件是不可能的,并且在命令行上使用 for 循环仍然迫使我输入每个文件的密码。

我更喜欢命令行解决方案,但 ant/maven 解决方案也可以。
系统是Linux。

如何对十几个 jar 文件进行签名,并且只提供一次密码?

最佳答案

这是来自 PSCode 的 Ant 构建文件的片段 - 它签署了一系列 Jars。诀窍在于 foreach 元素。

<target name="createjars"
depends="compile"
description="Jars the compiled classes">
<mkdir dir="${build}/jar/" />

<foreach target="jar.package" param="package" inheritall="true">
<path>
<dirset dir="${src}/java/org/pscode" includes="**/*" />
</path>
</foreach>
</target>

..和..

<target name='jar.package'>
<script language='javascript'>
<![CDATA[
prop = pscode.getProperty('package');
index1 = prop.lastIndexOf('pscode') + 7;
index2 = prop.length();
prop1 = prop;
path = prop1.substring( index1, index2 );
path2 = path.replaceAll('\\\\','/');
pscode.setProperty('path', path2 );

name = path2.replaceAll('/','.');
pscode.setProperty('jar.name', name + '.jar' );
]]>
</script>

<xmlproperty file="${src}/java/org/pscode/${path}/manifest.xml" />
<!-- echo message='jar.name: ${jar.name} *** ${application.title}' / -->
<if>
<not>
<uptodate targetfile='${build}/dist/lib/${jar.name}' >
<srcfiles dir= '${build}/share/org/pscode/${path}' includes='*.class'/>
</uptodate>
</not>
<then>
<jar
destfile='${build}/dist/lib/${jar.name}'
index='true'
update='true'>
<manifest>
<attribute name="Implementation-Title" value="${application.title}" />
<attribute name="Implementation-Vendor" value="${vendor}" />
<attribute name="Implementation-Vendor-Id" value="org.pscode" />
<attribute name='Implementation-Version' value='${now}' />
</manifest>
<fileset dir='${build}/share'>
<include name='org/pscode/${path}/*.class' />
</fileset>
<fileset dir='${src}/java'>
<include name='org/pscode/${path}/*.png' />
<include name='org/pscode/${path}/*.jpg' />
<include name='org/pscode/${path}/*.gif' />
<include name='org/pscode/${path}/*.xml' />
<include name='org/pscode/${path}/*.html' />
<include name='org/pscode/${path}/*.ser' />
</fileset>
</jar>
</then>
</if>

<!-- If the Jar is updated, any previous signatures will be invalid, it
needs to be signed again. We cannot use the issigned condition since
that merely checks if a Jar is signed, not if the digital signatures are
valid. -->
<exec
executable='${jar.signer}'
resultproperty='jar.signer.result.property'
outputproperty='jar.signer.output.property'>
<arg value='-verify' />
<arg value='${build}/dist/lib/${jar.name}' />
</exec>

<if>
<or>
<not>
<equals arg1='${jar.signer.result.property}' arg2='0' />
</not>
<or>
<contains
string='${jar.signer.output.property}'
substring='unsigned'
casesensitive='false' />
<or>
<contains
string='${jar.signer.output.property}'
substring='SecurityException'
casesensitive='false' />
</or>
</or>
</or>
<then>
<signjar
jar='${build}/dist/lib/${jar.name}'
alias='pscode'
storepass='${sign.password}'
force='true'
verbose='${verbose}'
keystore='${user.home}/${sign.pathfilename}' />
</then>
</if>

</target>

关于java - 如何使用 jarsigner 签署十几个 JAR 文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10911058/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com