Truststore. Jks Can Not Be Found When Run Spring Boot Kafka App Using Java -Jar

My app can be run in eclipse or via gradlew bootRun. But when I build a 'fat' jar file app.jar via gradlew build, and then start app via java -jar app.jar, I get below error:

ERROR o.a.k.c.s.ssl.SslEngineBuilder - Modification time of key store could not be obtained: kafka_truststore.jks java.nio.file.NoSuchFileException: kafka_truststore.jks

The kafka_truststore.jks is defined in application.properties like this

kafka.truststore_location=src/main/resources/kafka_truststore.jks

It is used in kafka client config class like below

@Value("${kafka.truststore_location}") private String trustStoreLocation;

props.put("ssl.truststore.location", trustStoreLocation);

Dose any one know how to resolve this issue? Thanks.

2 Answers

When you build the jar, all the files from resources usually get packed at the project root.

so in order to get the trustore,jks working, change your application.propeties as below

kafka.truststore_location=classpath:kafka_truststore.jks

This will work from IDE and when you run the fat jar independently.

4

Solved !! you can just copy the java jdk filr to /tmp folder and it works !!

cp /usr/lib/jvm/<your-jdk-package>/jre/lib/security/cacerts /tmp/kafka.client.truststore.jks

In my case, it is:

cp /usr/lib/jvm/java-1.8.0-openjdk-amd64/jre/lib/security/cacerts /tmp/kafka.client.truststore.jks

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Marcus Vance

Marcus Vance

Cybersecurity & Digital Privacy Researcher

Marcus Vance is a cybersecurity auditor and technology writer dedicated to educating the public about online safety, data privacy regulations, enterprise security, and emerging cyber threats.

Share this article
Twitter Facebook Pinterest