Skip to main content

Loading properties from jar file in a Webapp

1 reply [Last post]
aminjava
Offline
Joined: 2008-10-31

Hello Experts !!!..

I am trying to load a properties file from a jar file this is the structure

WEB_INF/lib/workflow.jar

from my servlet and web servbice i have to read load this file

this is my code
Properties props = new Properties();
ClassLoader loader = ClassLoader.getSystemClassLoader();

System.out.println(loader.getClass().getName());

InputStream in = null;
if (loader != null) {
URL url = loader.getResource("com/comp/resource/workflow.properties");

if (url == null) {
in = loader.getResourceAsStream("com/comp/resource/workflow.properties");
}
if (url != null) {

in = url.openStream();
props = new Properties();
props.load(in);

System.out.println("property val :"+props.getProperty("PushAppImpl"));
}
else {
System.out.println("STILL NULL");
}
}

i dont get the properties file from t5he class loader , what is going wrong ?
other thing , this works fine when i run as a stand alone java client , thh SAME CODE works !!!

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
thevash
Offline
Joined: 2009-12-22

try this:

YourClassName.class.getResourceAsStream(...)