I have created a minimum Maven project with single child module in a cloned helios.
In the src / test / resource folder I've put a single file "install.xml". In the folder src / test / java, I have created a package with a single class that:
@Test public void doit () throws an exception {URL url = this.getClass () . . GetClassLoader () getResource ("install.xml"); Println (url.getPath ()); }
But when I run the code as a junior 4 unit test, I just get a NullPointerException. A hundred times before that has worked fine once. Any ideas?
I have followed this guide:
But still get the same error.
when you use
this.getClass (). GetResource ("myFile.ext")
getResource
will try to find resources relative to the package. If you use:
this.getClass (). GetResource ("/ myFile.ext")
getResource
will be treated as an absolute path and just call the classloader as you would like .
this.getClass (). GetClassLoader (). GetResource ("myFile.ext")
You can not use the /
, because all ClassLoader path is absolute and therefore there is not a valid first letter in the
/
path.
Comments
Post a Comment