July 21, 2006

Divide and rule - use multiple struts config files for one application

Too tired of searching through the long struts config file for the module you are working on? Get a new config file for your modules. All you need is to modify the web.xml to use multiple config files.

<servlet>

<servlet-name>action</servlet-name>

<servlet-class>

org.apache.struts.action.ActionServlet

</servlet-class>

<init-param>

<param-name>config</param-name>

<param-value>

/WEB-INF/struts-config.xml,

/WEB-INF/module1.xml,

/WEB-INF/module2.xml,

/WEB-INF/module3.xml

</param-value>

</init-param>

<load-on-startup>1</load-on-startup>

</servlet>

When the ActionServlet is loaded, Struts will merge the results of the specified configuration files into a single in-memory configuration. Just make sure that syntax of each file is correct.