It should be getResource("/install.xml");
The resource names are relative to where the getClass() class resides, e.g. if your test is org/example/foo/MyTest.class
then getResource("install.xml")
will look in org/example/foo/install.xml
.
If your install.xml
is in src/test/resources
, it's in the root of the classpath, hence you need to prepend the resource name with /
.
Also, if it works only sometimes, then it might be because Eclipse has cleaned the output directory (e.g. target/test-classes
) and the resource is simply missing from the runtime classpath. Verify that using the Navigator view of Eclipse instead of the Package explorer. If the files is missing, run the mvn package
goal.