Sunday, October 14, 2007

Resource loading in a jar file

If a resource is included together with the classes in the same Jar, one can load it
using the following command:


InputStream in = getClass().getResourceAsStream("/log4j.properties");


Note that slash is required if the resource is put on the top-level, otherwise
it should be at the same place as the calling class. Essentially, the above code
is different from below:


InputStream in = getClass().getResourceAsStream("log4j.properties");

No comments: