How can I access a configuration and/or log.properties file (stored under WEB-INF) in a web application?

Charles Cuozzo

I place the log.properties and the appconfig.xml file in the WEB-INF/classes directory. (appconfig.xml is the other configuration file I spoke of.)

I get the locations as a URL object using the following code:

String logFile = getInitParameter("logger");  // or just logFile = "log.properties"
URL logurl = this.getClass().getResource("/" + logFile);
if(logurl != null)
{
  PropertyConfigurator.configure(logurl);
}
else
{
  System.out.println("log.properties not found!!");
}

I do pretty much the same thing to get my appconfig.xml file read in and parsed. I simply convert the URL into a string format and use that to parse the XML.

0 Comments  (click to add your comment)
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

About | Sitemap | Contact