Sumarizing what I explained in Part 2, we need to create:
- A Main servlet extending Liferay's Main Servlet
- A Struts ModuleConfig, and a ModuleConfigFactory
- A TilesDefinitionFactory
- A HotDeployListener
If you've read previous entries you already know why we need all of these and what are the objectives of each class, so I'm just gonna provide you with some code so that you don't need to write it down. Just copy/paste that code into the correnponding classes, package it, deploy it, and take advantage of this!
Creating Struts ModuleConfigFactory and ModuleConfig
Creating the HotdeployListener
Once you've package that code, just :
- copy the resulting JAR file in Liferay's ROOT/WEB-INF/lib directory
- in ROOT app's web.xml:
- modify Main Servlet's class to be your new Main Servlet class
- add/modify Main Servlet's initParam configFactory to have your new ModuleConfigFactory class as value
That's all. After following those steps, any struts-config.xml file located inside WEB-INF's directory of a hook will be parsed and loaded by Struts engine (overriding existing ones if necessary), at runtime, so that those configurations can be used from then on. Same for tiles configurations found in tiles-defs.xml file in the same directory, and Spring config files.
Thing to keep in mind
- Be careful on using this features since other struts/tiles/spring definitions can be overridden accidentally.
- Struts configurations (mappings) lookup methods are not synchronized. This means that if you hot deploy a hook and new struts configurations are loaded, there may be some running threads trying to use one of these configurations before their struts configuration information has been synchronized with changes.