Friday, September 21, 2012

How to read resources from a jar file?

We should load it from the classpath instead of as a file if we want to be able to load it from a jar. We want the Class.getResourceAsStream() method or the ClassLoader.getResourceAsStream() method.

Example:
properties.load(MsgBuilder.class.getResourceAsStream("/errormessages.properties")