0

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?

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.