Cannot load keystore when running java -jar *.jar spring boot application
See original GitHub issueHi,
I have a kafka-keytore.jks file in src/main/resources and when I run the application with mvn spring-boot:run there are no exceptions but when I run the application with java -jar target/demo-0.0.1-SNAPSHOT.jar the following error occurs:
Caused by: java.io.FileNotFoundException: class path resource [kafka-keytore.jks] cannot be resolved to absolute file path because it does not reside in the file system: jar:file:/Users/aalmazan/demo/target/demo-0.0.1-SNAPSHOT.jar!/BOOT-INF/classes!/kafka-keytore.jks at org.springframework.util.ResourceUtils.getFile(ResourceUtils.java:217) ~[spring-core-5.0.7.RELEASE.jar!/:5.0.7.RELEASE] at org.springframework.core.io.AbstractFileResolvingResource.getFile(AbstractFileResolvingResource.java:133) ~[spring-core-5.0.7.RELEASE.jar!/:5.0.7.RELEASE] at org.springframework.boot.autoconfigure.kafka.KafkaProperties$Ssl.resourceToPath(KafkaProperties.java:945) ~[spring-boot-autoconfigure-2.0.3.RELEASE.jar!/:2.0.3.RELEASE] … 76 common frames omitted
If I unpack target/demo-0.0.1-SNAPSHOT.jar the kafka-keytore.jks.jks file is inside.
Here are the steps to reproduce the problem:
- Go to and generate new project skeleton with spring boot 2.0.3, demo artifact name and add
Kafkadependency. - Add the following properties to
src/main/resources/application.propertiesfile:
spring.kafka.ssl.key-password=testkey
spring.kafka.ssl.keystore-location=classpath:kafka-keytore.jks
spring.kafka.ssl.keystore-password=teststore
- Execute
mvn clean install - Execute
mvn spring-boot:run-> no error occurs - Execute
java -jar target/demo-0.0.1-SNAPSHOT.jar-> the error occurs
Issue Analytics
- State:
- Created 5 years ago
- Comments:7 (4 by maintainers)
Top Related StackOverflow Question
One possible workaround is to extract the keystore to a temporary file:
and
Yes, that should work ok for you. I don’t think there is any other choice, given the limitations of the Kafka clients.