java - jarsigner 无法在 java 中工作,因此构建失败

标签 java eclipse jar-signing

jarsigner 无法在 java 中工作,因此构建失败

  [signjar] jarsigner: unable to sign jar: no response from the Timestamping Authority. When connecting from behind a firewall an HTTP or HTTPS proxy may need to be specified. Supply the following options to jarsigner:
  [signjar]   -J-Dhttp.proxyHost=<hostname>
  [signjar]   -J-Dhttp.proxyPort=<portnumber>
  [signjar] or
  [signjar]   -J-Dhttps.proxyHost=<hostname> 
  [signjar]   -J-Dhttps.proxyPort=<portnumber> 

项目构建路径没有错误。所有依赖项都导入到构建路径中。

最佳答案

这是我理解的问题:

  • 您正在尝试使用 Ant“build.xml”文件构建项目。
  • 您正在 Eclipse 中运行构建。
  • 您正在无法访问互联网的虚拟机中运行 Eclipse。
  • 在 JAR 签名期间,当 jarsigner 尝试与时间戳机构 (TSA) 通信时,构建会失败。需要访问互联网才能与 TSA 交谈。

Also I am not sure why is this error encountered.

这是因为您正在尝试使用签名时间戳,并且您的构建系统没有直接的互联网访问权限,并且您没有没有以适当的方式提供 http 或 https 代理供 jarsigner 使用。

<小时/>

有几种方法可以解决这个问题。 (以下内容基于文档,我没有测试过。)

如果您有可用的互联网代理:

  • 最简单的方法是在“build.xml”中编辑“signjar”任务并添加“tsaproxyhost”和“tsaproxyport”属性,如 Ant manual 中所述。 .

  • 如果您在命令行上构建1,您应该能够按照 Proxy Configuration 的 Ant 说明进行操作。 。 (有两种方法...)

  • 如果您使用 Eclipse 运行构建,那么您可以找到用于运行 Ant 的 Eclipse“运行程序”配置,然后按照前面的项目符号添加命令行。

(我认为有关 -J-D... 选项的错误消息来自 jarsigner 实用程序本身。该建议仅在您是直接从命令行运行 jarsigner。这当然是另一种选择。)

如果您没有可用的代理(或者您只是厌倦了),另一种选择是编辑“signjar”任务以禁用签名。删除“tsaurl”和“tsacert”属性就可以了。

禁用时间戳将为您提供一个没有签名时间戳的签名 JAR。 Oracle Signature Timestamp Support 解释了其重要性文档:

"Prior to J2SE 5.0, the signature generated by jarsigner contained no information about w hen the signature was generated. With no other information available, systems/deployers (including users of the Java Plug-in) often based their validity assessment of a signed JAR file on the validity of the signing certificate. When the signing certificate expires, systems/deployers conclude that the signature, and hence, the JAR file, has expired. Because signing certificates typically expire annually, this caused customers significant problems by forcing them to re-sign deployed JAR files annually.

Starting in J2SE 5.0, jarsigner can generate signatures that include a timestamp, thus enabling systems/deployer (including Java Plug-in) to check whether the JAR file was signed while the signing certificate was still valid. In addition, APIs were added in J2SE 5.0 to allow applications to obtain the timestamp information."

<小时/>

1 - 我建议您下载并安装独立的 Ant,以便可以从命令行运行构建。

关于java - jarsigner 无法在 java 中工作,因此构建失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51592925/

相关文章:

java - java小程序网页上有x是什么意思?

java - Android ffmpgeg - 没有任何反应

c++ - Eclipse CDT : nothing could be resolved?

java - 严重 : A child container failed during start java. util.concurrent.ExecutionException

java - 函数的这一部分的名称是什么?

java - 如何衡量 SonarQube 7.0 中的安全性?

java - 如何测试接受命令行参数的并发 Java 程序?

Java Applet - "Block potentially unsafe components from being run?"消息

java - 如何使用 jarsigner 签署 apk?

maven - 如何判断哪个签名的 jar 导致 maven-shade-plugin 失败?