Reputation: 11078
I have a third party library that works with jUnit, but does not once deployed to tomcat. Digging into the code, I can see it fails here:
final String path = "/api-version.dat";
final InputStream stream = ClassLoader.class.getResourceAsStream(path);
The api-version.dat is located on jUnit test, but doing the same on Tomcat results in NullPointerException
due to Tomcat unable to get the api-version file. This file exist and it is located inside the third party jar. What I have tried so far:
Any thoughts?
Upvotes: 1
Views: 397
Reputation: 42020
In a Java EE enviroments use:
final InputStream stream = Thread.currentThread()
.getContextClassLoader()
.getResourceAsStream(path);
See more in Difference between thread's context class loader and normal classloader.
Upvotes: 1