I have a big issue doing something really stupid. That is to say open a stream to a resource file in my META-INF folder. I am working on a jar tool and on doing this:
InputStream schemaIS = this.getClass().getClassLoader().getResourceAsStream("/META-INF/schema.xsd");
I simply get a null! The project is built using maven and the xsd file ends up in the META-INF folder, but it still won’t work.
What I don’t understand is the theory behind it? How do the ClassLoader execute the lookup in the file system? How do I get my hands on the file?
Try removing first slash:
You need a leading slash if you are calling the
getResourceAsStreammethod on aClassobject. On aClassLoaderobject, the path is always absolute, and the leading slash is not necessary.