vrijdag 16 augustus 2013

reading properties from tomcat

Introduction

This actually an issue I ran into more then one time. Howto read and test properties needed from the conf folder on the tomcat server. The solution is quit simple.

The solution
             
               // get the conf folder inside the catalina home folder
File configDir = new File(System.getenv("CATALINA_HOME"), "conf");
               // reading the property file
File configFile = new File(configDir, propertyFileName);
InputStream properties = null;;
try {
                       //read it as a stream
                  properties = new FileInputStream(configFile);
                        //load the the stream into java.util.properties.
this.properties.load(properties);
} catch (FileNotFoundException fnfe) {
LOGGER.error("could not find   properties " + fnfe.getMessage());
} catch (IOException ioe) {
LOGGER.error("could not access  time properties " + ioe.getMessage());

}

have fun!