lundi 18 juillet 2016

ClassLoader getResource() in called jar uses resources from the caller

I have two java projects. Project B is a utility, meant to be packaged as a jar and called by other projects. Project A needs to call project B. However, when project B calls ClassLoader getResource(), it is loading resources from project A. How do I get it to load from project B? It seems like this should be easy, so I feel that I must be missing something simple. The following code is in the project B, called from project A. path/to/file.txt is in the resources folder in project B.

System.out.println(Paths.get(classLoader.getResource("path/to/file.txt").toURI()).toString());

Output: C:Users....projectAtargettest-classes

Aucun commentaire:

Enregistrer un commentaire