So I've been trying to deploy a project as a jar and it needs to read a file this way:
private static final String DEFAULT_PATH = "org/some/thing/cool/necesaryFile.xml";
public void readSomeFile() {
InputStream is = null;
try {
ClassLoader classLoader = SomeOtherClass.class.getClassLoader();
is = classLoader.getResourceAsStream(DEFAULT_PATH);
}
catch (IOException e) {
e.printStackTrace();
}
finally {
safeClose(is);
}
}
public static void safeClose(InputStream is) {
if (is != null) {
try {
is.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
I've tested this inside Eclipse and it works fine! Debugging I saw the path and there was no problem at all! When I deployed the jar with maven it showed no error, but when I try to run project A with the jar as a dependency, I get
java.lang.IllegalArgumentException: InputStream cannot be null
And checking the jar inside project A, I can't find the necesaryFile.xml that was there before deployed.
The path for the xml file was like this:
C:/coolUser/workspace/src/main/java/org/some/thing/cool/necesaryFile.xml
so it was inside cool package with some java class.
So my question is, is there a way to tell maven not to erase the file (if that's even what's happening) when deploying the jar? Moving the location of that xml file is not an option (or at least I hope not to do it)
The maven command :
mvn clean deploy -U -Dmaven.test.skip=true -DaltDeploymentRepository=coolRepo::default::${REPO_LOCATION}