I have a web application deployed as a war in Tomcat 6. I am trying to read a config file under WEB-INF/ from a java class packaged in a jar under WEB-INF/lib. I get:
The system cannot find the file specified
Code:
Properties props = new Properties();
File propsFile = new File(".\config.properties");
InputStream stream = this.getClass().getClassLoader().getResourceAsStream(propertiesFilePath);
if (stream != null){
props.load(stream);
log.debug("stream not null");
}
else
props.load(new FileInputStream(propsFile));
It works fine in a server in production but in our test server it doesn't. Could it be server config related?
Try this:
URL resource = new URL(this.getClass().getResource("."), "config.properties");
InputStream stream = resource.openConnection().getInputStream();