Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Understanding Thread.currentThread().getContextClassLoader().getResourceAsStream()

I am looking at a code example, and I am not sure what this means.

Thread.currentThread().getContextClassLoader()
    .getResourceAsStream("MyProperty.properties");

It appears that it looking to read a property file but I am not sure where MyProperty.properties is located.

I appreciate for any help, thanks.

like image 404
Tony Avatar asked Sep 28 '12 18:09

Tony


1 Answers

It appears that it looking to read a property file but I am not sure where MyProperty.properties is located.

As you currently have it there, that will look for the MyProperty.properties file at the top of your classpath. The could be in your src/main/resources directory or other src folder -- it would depend on how your application (jar/war) is built.

If you are building a jar then you should be able to unpack it and see your properties file at the top level of the jar. If you are building a war, maybe it should be in the WEB-INF/classes directory. Again, it depends on how it was built.

Typically the log4j.properties file is also at the top of the classpath so you may want to look for that file and put your property file alongside it.

like image 90
Gray Avatar answered Sep 20 '22 23:09

Gray