Dashboard > Community Wiki > ... > Developing with Magnolia > One war, multiple configs
One war, multiple configs Log In View a printable version of the current page.

Added by GrĂ©gory Joseph , last edited by Philipp Bracher on Jul 28, 2008  (view change)
Labels: 

One war file, multiple configs

Since 3.0 this feature is enabled by default. So you don't have to modify the web.xml.
Also note that the property files are cascaded so you should only put the properties into the specific files which override a default configuration. This is mainly used to configure a different repository configuration (home directory or configuration file).
A good example is how the magnoliaPublic webapp is configured.

RC3 introduced a new feature that makes customizing one war for author vs. public vs. some other server a bit easier. No need to keep two or more build trees around and in sync anymore (especially good if your a NetBeans person like me).

By default it's there, but not enabled. You'll see it as a default folder in WEB-INF/config. In that default folder is a readme.txt that gives some info, but not a lot. First, let me provide that readme here:

Default configuration directory used with info.magnolia.cms.servlets.PropertyInitializer.

Using the Magnolia PropertyInitializer you can easily bundle in the same webapp different set of configurations which are automatically applied dependending on the server name or the webapp name.
By default the initializer will try to search for the file in different location with different combination of servername and webapp: the default fallback directory will be used if
no other environment-specific directory has been added.

This is the list of location where the initializer will try to find a configuration file (can be overridden using the magnolia.initialization.file context parameter in WEB.xml)

  • WEB-INF/config/${servername}/${webapp}/magnolia.properties,
  • WEB-INF/config/${servername}/magnolia.properties,
  • WEB-INF/config/${webapp}/magnolia.properties,
  • WEB-INF/config/default/magnolia.properties,
  • WEB-INF/config/magnolia.properties

Now to set it up. That's relatively simple:

1. Create a folder under WEB-INF/config for each separate config naming them to match the name of the webapp. If you're deploying on different servers, nest these inside another folder named after your server.

For instance if developing a magnoliaAuthor and magnoliaPublic config, you'll have folders /WEB-INF/config/magnoliaAuthor and /WEB-INF/config/magnoliaPublic. If dealing with different servers, it might look like /WEB-INF/config/server1.com/magnoliaAuthor and /WEB-INF/config/server2.com/magnoliaPublic.

2. Copy the default folder's contents in to each folder and customize for each separate instance as needed. One of those things you'll probably want to change consistently is the magnolia.root.sysproperty value to something unique. Then change the log4j.xml files to match this new value. Finally change the log4j.config value in magnolia.properties to point to your customized log4j.xml file.

3. Open web.xml and comment out both the listener section for the standard initializer "info.magnolia.cms.servlets.Initializer" and the following context-param blocks. I would comment at first just to make it easy to role back if things don't work out right. Delete later when things are working well.

4. Add the following to your web.xml:

<listener>
      <description>Magnolia Property Initializer</description>
      <display-name>propertyInitializer</display-name>
      <listener-class>info.magnolia.cms.servlets.PropertyInitializer</listener-class>
    </listener>
    
    <context-param>
      <param-name>magnolia.initialization.file</param-name>
      <param-value>
        WEB-INF/config/$\{servername}/$\{webapp}/magnolia.properties,
        WEB-INF/config/$\{servername}/magnolia.properties,
        WEB-INF/config/$\{webapp}/magnolia.properties,
        WEB-INF/config/default/magnolia.properties,
        WEB-INF/config/magnolia.properties
      </param-value>
    </context-param>

5. Save and you're done. Deploy and watch the magnolia-debug.log files for any gotchas. It never fails for me to miss a setting at first and find out about it later when I'm analyzing the logs. Just change the name of your webapp, deploy, and the config used will change as well.

The list of paths in the magnolia.initialization.file context param above isn't anything magic. Define it as you like, what's shown here is the default used if it was missing. If you aren't deploying against different servers, take out the top two and work with the last three. It'll try in order from first to last until it finds a magnolia.properties file.

Here you can find complete config for two instances. It creates all repositories.
Have fun!

In its previous incarnation on JspWiki, this page was last edited on Feb 9, 2007 10:27:37 AM by Baky

Powered by a free Atlassian Confluence Open Source Project License granted to Magnolia International. Evaluate Confluence today.
Powered by Atlassian Confluence 2.7, the Enterprise Wiki. Bug/feature request - Atlassian news - Contact administrators