Mavenized seam, exploded ears and hot deployment
barakka Jan 6, 2009 1:56 PMThe other day i was trying to have the seam hot deploy feature working with my mavenized, ear-packaged, seam application running on JBoss 4.2.3. As this proved tricky (for me) and made me waste a lot of time, I though it could be helpful for others to write down how in the end I managed to get it working.
In order to have hot deployment working you need to have the application deployed to JBoss as an exploded ear, as you then need access to the war/WEB-INF/dev directory to redeploy. So the first problem was how to get the exploded ear working. My original ear was packaged like this:
ear.ear - ejb.jar - war.war ->META-INF application.xml etc. ->lib jboss-seam.jar all others jars
with jboss-seam.jar referenced as a module in application.xml
... <module> <ejb>lib/jboss-seam.jar</ejb> </module> ...
This configuration worked just fine when the application was deployed as a normal ear, but
unfortunately it created the nasty problem of the SeamPhaseListener being installed twice when deployed as an exploded ear. After many trials, I discovered that apparently JBoss was deploying the seam jar twice, once as a lib and once as module. To solve the problem, I needed to change the location of the seam jar and put it in the root directory (and of course change accordingly the application.xml). So the final layout looks like:
ear.ear - ejb.jar - jboss-seam.jar ->war.war - all xhtml resources, properties, page.xml, etc. ->META-INF ->WEB-INF - all descriptors (components.xml, web.xml, etc.) ->classes - non hot deployment classes. - seam.properties ->dev - hot deployment classes. ->META-INF application.xml etc. ->lib all others lib jars
and application.xml:
... <module> <ejb>jboss-seam.jar</ejb> </module> ...
Finally, to enabled hot deployment I created a separated maven module that I use to contain all needed classes during development (which then I move to the proper modules when done).
A couple of maven-antrun-plugin are then used both to copy and explode the ear to jboss during the packaging phase (in a separated development profile in the ear pom), and to copy the hot deployment classes (in hot module). For instance like this:
<plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-antrun-plugin</artifactId> <version>1.1</version> <executions> <execution> <id>hot-deploy</id> <phase>process-classes</phase> <configuration> <tasks> <copy toDir="${jboss.deploy.dir}/ear.ear/web.war/WEB-INF/dev" overwrite="true"> <fileset dir="${project.build.directory}/classes" > <include name="**/*.class"/> </fileset> </copy> </tasks> </configuration> <goals> <goal>run</goal> </goals> </execution> </executions> </plugin> </plugins>
The important point here, however, is that for ear exploded deployment the seam jar can't be put in the lib directory but must be placed in the root ear directory. Hope this can help someone else to avoid some wasted time to figure this out.
Best,
Riccardo.