February 24, 2004
Locating the configuration files for my J2EE app

Arrrrrgh! I just can't believe that this is hard! (Or perhaps it's just me that finds this hard. That's not so difficult to believe.)

OK, so, the J2EE application we are working on needs some configuration, so I've monkied up a quick Digester based configuration file reader. That should have been the hard bit, but it's been a piece of cake. Digester is great!

But now I need to get it to read the configuration file from within my J2EE application. So where do I put this file, and how do I tell Tomcat (or whatever) where to look for it?

I've currently got this file in WEB-INF/config.xml, which feels right. But Tomcat can't find it given just this as a file path. I suppose that I need to prepend the document root to this - but how do I find that? (I'm currently trying to read this file in a ServletContextListener's contextInitialized method.)

Naturally, I'd rather not use anything Tomcat specific if I can help it. But I did try this:

final ProxyDirContext proxyDirContext = (ProxyDirContext) servletContext.getAttribute("org.apache.catalina.resources");
final String docBase = proxyDirContext.getDocBase();

But unluckily (or perhaps luckily) this didn't work. It *would* work from a Servlet, I think, but the org.apache.catalina.resources context attribute doesn't seem to exist as the context is initialised.

Arrrrrgh!

Posted to Java by Simon Brunning at February 24, 2004 12:49 PM
Comments
Post a comment
Name:


Email Address:


URL:



Comments:


Remember info?