question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Can't find the location of file keystore when running as jar

See original GitHub issue

I use Spring Boot 1.4.0. And I find that tomcat can’t read the keystore conatined in a jar. But how can I load the keystore in a jar.

The configuration about SSL:

server:
  port: 8443
  ssl:
    enabled: true
    key-store: classpath:keystore.jks
    key-store-password: pass
    key-alias: pass
    #protocol: TSL
    enabled-protocols: TLSv1,TLSv1.1,TLSv1.2

The Exception:

java.io.FileNotFoundException: class path resource [xx.jks] cannot be resolved to absolute file path because it does not reside in the file system:jar:file:/C:/xx/xx/xx/xx/xx/target/xx-1.0-SNAPSHOT.jar!/xx.jks

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:16 (6 by maintainers)

github_iconTop GitHub Comments

9reactions
momo159commented, May 4, 2017

Thanks. I fixed it by your samples.

0reactions
priyanka28-langcommented, Jan 30, 2021

My application files has :

stargate-filter.truststore=standard_trusts.jks

and I can’t even change the code for getResource as I am importing some dependency …

ks = KeyStore.getInstance(KeyStore.getDefaultType());
URL resource = this.getClass().getClassLoader().getResource(config.getTruststore());
if(resource == null) { 
    System.out.println("Could not find the truststore located at [" + config.getTruststore()+ "]");
} else {
    File file = new File(resource.toURI());
    FileInputStream fis = new FileInputStream(file);
    ks.load(fis, config.getTruststorePassword().toCharArray());
}

In my local it works fine, but deploying it to any external server (k8) I get this as URI is not hierarchical … and if i copy it o some location and provide the path … I get exception “System.out.println(“Could not find the truststore located at [” + config.getTruststore()+ “]”);”…

Any suggestions …

Read more comments on GitHub >

github_iconTop Results From Across the Web

spring-boot executable war keystore not found - Stack Overflow
You should move keystore.jks out of your jar and update server.ssl.key-store with its location on the file system.
Read more >
jarsigner
The jarsigner command uses key and certificate information from a keystore to generate digital signatures for JAR files. A keystore is a database...
Read more >
How to use jarsigner to sign JARs files example | TechTarget
With the keys create and stored, export the server certificate to the filesystem so we can use it in the jarsigner's sign and...
Read more >
EV Code Signing Certificates for Java - DigiCert.com
If after running the keytool or jarsigner command, the program pauses and does not prompt you for a password, unplug the device (token)...
Read more >
Spring Cannot Find Key Store File - ADocLib
keytool exportcert rfc alias tomcat keystore keystore.jks file selfsigned.crt ... Ask questionsCan't find the location of file keystore when running as jar.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found