Class.getResource() returns URL of source, not class
We use maven with the usual src/ and target/ directories. In our code we have the following which is used for things like programmatically mapping our hibernate classes.
public static File getDirectoryFile(Class<?> classOfResource) {
URL classResource = classOfResource.getResource("");
String classDirectory = classResource.getFile();
return new File(classDirectory);
}
If classOfResource is 'Foo', I am expecting the resulting path to be target/<.war-name>/<path-to>/Foo(.class). In fact, that's exactly what is returned when running in Eclipse and Tomcat. But with IntelliJ the path is returned as src/<path-to>/Foo(.java). Needless to say everything fails after that.
The project was imported from the maven pom. I tried making sure target/<war-name> is not excluded in the module definition to no avail.
Am I missing something obvious or is IntelliJ doing something weird?
Thanks
Please sign in to leave a comment.
A small test case project to reproduce this issue would be appreciated.
Thanks for the response Serge. I have some emergencies to deal with first so I'll get back to you after dealing with those.