Home > Software design >  Files not found in JAR FIle
Files not found in JAR FIle

Time:04-14

I am trying to find a folder containning PDF's . Everything works when the backend and frontent is not a Jar file. My question is how do you locate files ,if it is in a JAR, all I am recieving is a file not found exception

Tried adding the file to my resources folder but still nothing. What am I missing?

Example of my code and where the folders are save

CodePudding user response:

This can be accomplished in a number of ways, here are a couple:

// get the resources as a URL
URL resource = getClass().getClassLoader().getResource(
    "static/test/TrainingDocuments/SuperUser/2/PartnerInformation/PartnerInformation.pdf");

// get the resource as a classPathResource
ClassPathResource classPathResource = new ClassPathResource(
    "static/test/TrainingDocuments/SuperUser/2/PartnerInformation/PartnerInformation.pdf");

// get the resource directly as a stream
InputStream resourceAsStream = getClass().getClassLoader()
    .getResourceAsStream("static/test/TrainingDocuments/SuperUser/2/PartnerInformation/PartnerInformation.pdf");
  • Related