java - 在 jar 中找不到 KeyStore 文件,尽管存在于 jar 中

标签 java tomcat ssl https keystore

我设置了 Connector属性为

      LOGGER.debug("ksPath=>" + ksPath);
      httpsConnector.setAttribute("keystoreFile",ksPath);
      httpsConnector.setAttribute("keystorePass", keyStorePass);
      httpsConnector.setAttribute("clientAuth", "false");
      httpsConnector.setAttribute("sslProtocol", "TLS");
      httpsConnector.setAttribute("sslEnabledProtocols", tlsProtocols);
      httpsConnector.setAttribute("SSLEnabled", true);
      Connector defaultConnector = tomcat.getConnector();
      defaultConnector.setRedirectPort(port);

我在日志中看到的内容(运行时)

ksPath=>jar:file:/shn/lp/main-1.0-SNAPSHOT-jar-with-dependencies.jar!/my.keystore

但是,部署失败,我看到日志为

SEVERE: Failed to load keystore type JKS with path /shn/lp/jar:file:/shn/lp/main-1.0-SNAPSHOT-jar-with-dependencies.jar!/my.keystore due to /shn/lp/jar:file:/shn/lp/main-1.0-SNAPSHOT-jar-with-dependencies.jar!/my.keystore (No such file or directory)
java.io.FileNotFoundException: /shn/lp/jar:file:/shn/lp/main-1.0-SNAPSHOT-jar-with-dependencies.jar!/my.keystore (No such file or directory)
    at java.io.FileInputStream.open(Native Method)
    at java.io.FileInputStream.<init>(FileInputStream.java:146)
    at org.apache.tomcat.util.net.jsse.JSSESocketFactory.getStore(JSSESocketFactory.java:413)
    at org.apache.tomcat.util.net.jsse.JSSESocketFactory.getKeystore(JSSESocketFactory.java:319)
    at org.apache.tomcat.util.net.jsse.JSSESocketFactory.getKeyManagers(JSSESocketFactory.java:577)
    at org.apache.tomcat.util.net.jsse.JSSESocketFactory.getKeyManagers(JSSESocketFactory.java:517)
    at org.apache.tomcat.util.net.jsse.JSSESocketFactory.init(JSSESocketFactory.java:462)
    at org.apache.tomcat.util.net.jsse.JSSESocketFactory.createSocket(JSSESocketFactory.java:209)

观察

jar:file:/shn/lp/main-1.0-SNAPSHOT-jar-with-dependencies.jar!/my.keystore 

不同于

/shn/lp/jar:file:/shn/lp/main-1.0-SNAPSHOT-jar-with-dependencies.jar!my.keystore

后者以/shn/lp/开头

但是断言,我看到该文件实际上存在于 jar 中

jar -tvf /shn/lp/main-1.0-SNAPSHOT-jar-with-dependencies.jar | grep my.keystore
  4704 Tue Jun 09 09:29:26 PDT 2015 my.keystore

这是怎么回事?

如何解决这个问题?

最佳答案

它似乎不理解协议(protocol),可能是因为缺少前导斜线?你试过吗:

 String ksPath = this.getClass().getResource("/my.keystore").getFile();

关于java - 在 jar 中找不到 KeyStore 文件,尽管存在于 jar 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30739103/

相关文章:

java - 处理自定义 header 中的 jsessionid (Tomcat 6)

java - 用于 MS SQL Server 的 Eclipse 中 Tomcat 的连接池

c# - 无法使用权​​限 'apps.ika.gr' 为 SSL/TLS 建立安全通道

java - 如何使用微服务架构处理共享数据源

java - 编译警告 - 弃用且未定义serialVersionUID

C# ArrayList 的 Java 等效项

java - Eclipse 间歇性无法创建 Java 虚拟机

java - 在 windows 机器上生成的 keystore 可以在 unix 机器上使用

ssl - 服务器发送致命警报 : handshake_failure

Java 11 + Chrome/Firefox = TLS 解密错误