I was using the following code to read a file from the classpath:
Files.readAllBytes(new ClassPathResource("project.txt").getFile().toPath())
This worked fine when project.txt
was in src/main/resources
of my WAR. Now I refactored code and moved certain code to a JAR. This new JAR now includes src/main/resources/project.txt
and the code above. Now I get the following exception when reading the file:
java.io.FileNotFoundException: class path resource [project.txt]
cannot be resolved to absolute file path because it does
not reside in the file system:
jar:file:/usr/local/tomcat/webapps/ROOT/WEB-INF/lib/viewer-1.0.0-SNAPSHOT.jar!/project.txt
I'm still executing the WAR in a Tomcat container.
How can I fix this?