2

I have some amount of child maven modules in parent module. How can I get access from one module to resources of another and to have this solution stable in jar file ? I tried something like: (resource.txt - is situated in first module, and code is executing in second)

String pathToFirstModuleResource = ClassFromFirstModule.class.getClassLoader().getResource(resource.txt).getFile();

But it points me to ...firstmodule/target/classes/resource.txt, so it works almost good, but returns not a resource folder, but target/classes. Why it returns this targets folder, though should to return ...firstmodule/resources/resource.txt?

Junkwin
  • 63
  • 9
  • see this post may be helpful for you: https://stackoverflow.com/questions/15749192/how-do-i-load-a-file-from-resource-folder/46452118#46452118 – ArifMustafa Jan 12 '18 at 13:34

1 Answers1

2

Why it returns this targets folder, though should to return ...firstmodule/resources/resource.txt?

No. It looks like you configured resources being threaded by your IDE as a souce folder.
Therefore the folder resources only exist in your development environment. At runtime the file is simply copied to the root of your jar, which merely is the content of target/classes.

Timothy Truckle
  • 15,071
  • 2
  • 27
  • 51