如何使用 Ant 检查签名的 jar 文件?
我使用 Ant signjar 任务 签署 jar 文件,现在我想先测试一下部署。
我可以检查一下,
jarsigner -verify sbundle.jar
但我不知道是否可以用 Ant 做同样的事情?
I sign jar files with the Ant signjar task and now I want to test before deploy.
I can check with
jarsigner -verify sbundle.jar
but I do not know if it is possible to do the same with Ant?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
另一种方法是基于 Maven 脚本进行构建。
Maven 确实提出了
jarsigner:verify< /code>
插件
如果这不是一个有效的可能性,您仍然可以使用
Exec
Ant任务直接调用jarsigner
命令。如果返回码设置正确,您可以添加属性
failonerror
(如果命令退出时返回码不是 0,则停止构建过程。)An alternative would be to base your build on a maven script.
Maven does propose the
jarsigner:verify
pluginIf that is not a valid possibility, you still can use the
Exec
Ant task to directly call thejarsigner
command.If the return code is correctly set, you can add the attribute
failonerror
(Stop the build process if the command exits with a return code other than 0.)以下 Ant 代码可用于验证 JAR 文件签名。一旦遇到签名无效或缺失的 JAR 文件,脚本就会失败。
请注意,for 任务需要 ant-contrib。
The following Ant code can be used for verifying JAR-file signatures. The script will fail as soon as it encounters a JAR-file where the signature is not valid or where it is missing.
Note that ant-contrib is required for the for task.
蚂蚁条件报价“已分配”。
“测试 jarfile 是否已签名。如果传递了签名的名称,则检查文件是否存在该特定签名;否则检查文件是否存在任何签名。它不执行严格的签名验证;它只执行寻找签名的存在。
此条件是在 Apache Ant 1.7 中添加的。”
来自 Ant 条件
Ant conditions offer "issigned".
"Test whether a jarfile is signed. If the name of the signature is passed, the file is checked for presence of that particular signature; otherwise the file is checked for the existence of any signature. It does not perform rigorous signature validation; it only looks for the presence of a signature.
This condition was added in Apache Ant 1.7."
From Ant conditions
您可以使用 Ant 中的VerifyJar 任务来执行此操作。这是 Ant 帮助的链接
https://ant.apache.org/manual/Tasks/verifyjar.html
一次验证多个 JAR 文件的示例代码。
You can use the VerifyJar Task in Ant to do this. Here is the link to Ant help
https://ant.apache.org/manual/Tasks/verifyjar.html
Sample code for Verifying multiple JAR files at once.
基于@torkildr 的回答。
可以使宏将嵌套路径或文件集传递到 ant-contrib 任务。
Based on @torkildr's answer.
It's possible to make macro pass nested path or fileset to ant-contrib for task.