i have a maven module BaseProject with java classes in src/main/java
. Some classes are loading xml-files from the src/main/resource
folder.
That works pretty nice.
I have a second maven project TestProject that has uses the BaseProject as dependency.
TestProject is my JUnit test project, so there are classes only in src/test/java
.
If I use some of the classes from the BaseProject that load any resource I get a null
because the resource file can not be found.
I assume that the src/main/resource
folder from my TestProject is considered in this situation as the place to look for the resource files.
So how do i load the resource files in the BaseProject in a way that it will look always in its own src/main/resource
folder?
And here is how i do it at the moment:
InputStream inputStream = MyBaseClass.class
.getResourceAsStream(
"foo/bar/hello.xml" );
String content = new Scanner( inputStream, "UTF-8" ).useDelimiter( "\\Z" ).next();