On Fri, 25 Mar 2005 18:35:12 +0000 (UTC), John Brayton <[EMAIL PROTECTED]> wrote: > Laurent <lg83news <at> free.fr> writes: > > I have a few settings in my webapp (address of the LDAP server, location > > of 2 or 3 files), which are in the source code at the moment. This makes > > it difficult to change them (and I have to recompile every time). > > I like to store settings that a system administrator will need to be able to > change in a configuration "properties"-style file, outside of the webapp > directory or ".war" file. XML-based configuration files may be appropriate > for > applications where the configuration options are more complex. Other options > include the WEB-INF/web.xml file or, as you said, resource files. > > My reasoning for storing them completely outside of the webapp or ".war" file > is: > > * I think it allows you to communicate what you consider application > "configurations" that a system administrator will need to update. Everything > else (Java code, JSP's, Struts and Tiles Config Files, etc.) is "code" and > part > of the application, and therefore not expected to be change once released to > system administrators. > > * When you release a webapp update, the system administrator can safely > overwrite the old webapp without losing configuration changes. Of course, you > will likely still need to merge new configuration parameters as part of many > webapp updates. >
There's a third benefit to storing information like this outside of the war file -- you can take the same WAR and deploy it, unchanged, on a development server, a pre-production testbed, or a production server. This is the use case that JNDI environment variables were designed for in J2EE. Many of you are probably familiar with using JNDI data sources to configure JDBC data sources in a way that is totally external to your webapp. What is less commonly known is that you can do the same with configuration properties, using <env-entry> elements. As an example, lets say you wanted to store the URL of your LDAP server in some externally configurable spot. If you put an entry like this in your web.xml file: <env-entry> <env-entry-name>ldapURL</env-entry-name> <env-entry-type>java.lang.String</env-entry-type> </env-entry> then your initialization code can retrieve it easily: InitialContext context = new InitialContext(); String ldapURL = (String) context.lookup("java:comp/env/ldapURL"); and the actual value is configured using the admin tools (or configuration files) of your favorite server. For Tomcat, for instance, you put an <Environment> entry in the server.xml file: http://jakarta.apache.org/tomcat/tomcat-5.0-doc/config/context.html#Environment%20Entries Craig > John > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > > --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]