Resource in JAR
From email dated 18/11/2005 [m2] where to put test data
it may be a little hacky, but what I’ve used is:
ClassLoader loader = getClass().getClassLoader();
String resourceName = "/path/to/test.xslt";
URL resource = loader.getResource(resourceName);
File testFile;
if (resource != null) {
testFile = new File(resource.getPath());
} else {
throw new SomethingException(..);
}
From email dated 05/06/2006 Referencing Files from a Unit Test
I think this is what you’re looking for:
Re: Referencing .properties files in the CLASSPATH in test
this.getClass().getClassLoader().getResourceAsStream(...
Notes
I think path separators when getting resources from the classpath must be a forward slash.