ITMan
ITMan

Reputation: 11

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.

Upvotes: 0

Views: 21178

Answers (2)

ashique
ashique

Reputation: 1285

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

Upvotes: 0

vishnu g
vishnu g

Reputation: 109

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.

Upvotes: 1

Related Questions