0

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?

Kalamarico
  • 5,466
  • 22
  • 53
  • 70

1 Answers1

2

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.

Rajesh J Advani
  • 5,585
  • 2
  • 23
  • 35