I have my restlet.Component deployed in Tomcat, in this, i read a configuration file of my app:
this.properties.load(new FileInputStream("config/conf.properties));
I have got a java.io.FileNotFoundException
My webapp structure is:
/mi-webapp
/config
conf.properties
/WEB-INF
/classes
/lib
web.xml
How can i get the real path in restlet? i read about ServletContext.getRealPath()
but it's a bad practice, how do you recommend?
Move the config directory inside WEB-INF/classes
and use this code instead:
URL url = this.class.getClassLoader().getResource("config/conf.properties");
try {
this.properties.load(url.openStream());
} catch (IOException e) {
System.out.println("Couldn't open/load properties file");
}
This way you load the file from the classpath which is within the scope of your application anyway, and doesn't result in any security holes.