I have a class which needs to do some https request.
Just in case the ssl truststore and keystore are not set, the jar which contains my class, has them in its resource folder.
My class is being dynamically loaded by some classloader I have no control about and now when I do
getClass().getClassLoader().getResourceAsStream("keystore.jks");
the resource is not being found.
My theory on this is that getClassLoader
returns the classloader returns the classloader from a webserver, which probably isn't able to find the resource keystore.jks
in the jar file.
Any help is appreciated.
I found a way around the problem. I can use MyClass.class.getResourceAsStream("/keystore.jks");
to load the resource properly.
I am not exactly sure why it works though.
When I was using MyClass.class.getClassLoader().getResourceAsStream("keystore.jks");
it wasn't working. Although I think I read somewhere that Class.getResource()
with a leading /
is the same as ClassLoader.getResource()
without one.