Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

How to read property files?

I have a problem with a small web-app that I try to use on a SAP J2EE server.

The app was developed and tested on JBoss and there it was no problem to read the properties file with the following code:

...
URL resource = getClass().getResource("/WEB-INF/my.properties");
propertyStream = resource.openStream();
Properties properties = new Properties();
properties.load(propertyStream);
...

The properties file is deployed in the WEB-INF directory of the WAR. Seems the class loader can't find that file.

Could anybody explain what's wrong with the above code?

Former Member
Former Member replied

By default, the directory WEB-INF is not part of a web application's classpath.

Put the properties file into WEB-INF/classes and use

URL resource = getClass().getResource("/my.properties");

to load it.

Best regards,

Jens

0 View this answer in context
Not what you were looking for? View more on this topic or Ask a question