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

时间:2015-06-09 17:39:48

标签: 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

它有什么用?

如何解决此问题?

1 个答案:

答案 0 :(得分:0)

似乎它不理解协议,可能是因为缺少前导斜杠?你试过了吗?

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