Skip to Content
avatar image
Former Member

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?

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

1 Answer

  • Best Answer
    avatar image
    Former Member
    Apr 04, 2008 at 06:42 AM

    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

    Add comment
    10|10000 characters needed characters exceeded