Home > database >  getResourceAsStream returns null under Thread.currentThread.getContextClassLoader().getClass()
getResourceAsStream returns null under Thread.currentThread.getContextClassLoader().getClass()

Time:07-27

So The currently the loading configuration used by the library is

ClassLoader loader = Thread.currentThread().getContextClassLoader();
InputStream in = loader.getClass().getResourceAsStream("/properties/a.properties") // null

But when I tried to debug the application, the following expression contains the file

loader.getResourceAsStream("properties/a.properties")

I am using IntelliJ IDE and Maven build tool. The resources are copied into the target folder. And using IntelliJ run command to run the class currently.

Since the code is from the library, I can't modify it. What is the problem here and how it can be solved?

CodePudding user response:

One possible workaround is to downgrade the Java version to a non-module version (less than 9), so that the code works.

  • Related