In src/main/resources I have a folder files. The goal is to read the files and use them in the code below

public void init() {
  File jks = null;
  try {
      final FileInputStream fin = new FileInputStream(ResourceUtils.getFile("classpath*:files/prod-apicrypt.cer"));
    jks = ResourceUtils.getFile("classpath*:files/mykeystore.jks");
}catch(Exception e){

This works in the IDE and when I do mvn spring-boot:run but when I create the jar and I try to run it I get FileNotFoundException from the .cer file. I suppose the same will happen for the keystore as well.

The problem is that I cannot just do an Inputstream and read the file line by line as I find in other replies.

I think there must be something fundamental that I am missing because Spring Boot surely has a way to read files from the classpath. I just don't know what.

0 Answers