Geek Geek - 1 year ago 79
Java Question

properties file in Web project

I have all my programming code packaged in a jar file. This Jar file i will be placing in my dynamic web project to execute the logic in a jar.

But jar file has some logic which reads a .properties file to get some configuration values.

When i run my web project for the logic i get a error conf\ (The system cannot find the path specified)


I have following code for reading the properties file.

String propFileName = "conf/";
Properties prop = new Properties();

Any suggestion to resolve this issue plz.

I have also tried with

String propFileName = "conf/";
File file = new File(propFileName);
Properties prop = new Properties();
FileInputStream fileInput = new FileInputStream(file);

Answer Source

Your approach based on Class#getResourceAsStream(name) will only work if and only if your file is accessible from the ClassLoader of your calling class and here what you have directly under WEB-INF is not accessible, you should move conf/ in WEB-INF/classes instead and use /conf/ as resource name to make it get the file from the root not from the package of your calling class.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download