Saturday, 13 January 2007

Configuring a webapp

One thing I miss in J2EE webapps is a good way to configure the application outside the .war file. I want to be able to ship a .war file together with a properties file that the user can edit without having to unpack and re-pack the .war file. I also want to be able to deploy multiple instances of the same webapp in a container. Each having its own properties file.

There are a number of ways for a webapp to access properties.

  • A file under the web application root using ServletContext.getResource(AsStream)(). The problem with this is obviously that the file is inside the .war file.

  • Through the class path using Class.getResource(AsStream)(). Here you can access files outside the .war file. But there is a problem finding out what file to actually load in a particular webapp. At least if you use the init() method of a servlet. If you deploy several instances of the same webapp the thing that will be different is the context path that they are deployed under. And this information is only available in the HttpServletRequest object, not in the ServletContext.

  • Through system properties. This has the same problems as using the classpath and it may also not always be possible to set system properties parameters when starting the jvm.

I have installed a number of web application where I have had to find a property file deep inside the application server's deployment directories and edit it. Is there really no better way?

No comments: