Load properties file in JAR?

Posted by apryor48 on Stack Overflow See other posts from Stack Overflow or by apryor48
Published on 2010-05-12T00:40:30Z Indexed on 2010/05/12 0:44 UTC
Read the original article Hit count: 399

I'm having trouble when one of the jars that my web app depends on tries to load a properties file from within the jar. Here is the code in the jar.

static
{
    Properties props = new Properties();
    try 
    {
        props.load(ClassLoader.getSystemResourceAsStream("someProps.properties"));
    } catch (IOException e) 
    {
        e.printStackTrace();
    }
    someProperty = props.getProperty("someKey");
}

The properties file is in my "src/main/resources" directory of the Maven project. When I run this code from my junit test in Eclipse, it executes just fine. When the project is built with Maven into a jar, and included as a dependency in my webb app, it fails to locate the properties file. I know that the properties file is at the base directory of the depended on jar, I don't know how to fix this.

Please help!

© Stack Overflow or respective owner

Related posts about java

Related posts about properties