Reputation: 1
I work with the follwing project:
Test-Project
/lib/classA.jar
/src/main/java/org/test/classB.java
/src/main/resources/log.txt
In classA.jar, I work with the ClassLoader.getSystemClassLoader()
to get the path of the "log.txt" file. In the project of classA.jar, there is no problem with that.
But when I use the jar in the Test-Project I get the follwing path to the "log.txt" file:
/lib/classA.jar!/log.txt
Is there a way to get the classloader from Test-Project into to the jarfile?
Upvotes: 0
Views: 91
Reputation: 324
For accessing to a resource file you should use Class#getResourceAsStream for reading this file.
InputStream stream = Class.class.getResourceAsStream("/log.txt");
Note: a jar file is an archive, which is meant to be unchanged, if that is really a log file you shouldn't store it inside a jar file.
Upvotes: 1