My favorites | Sign in
Project Logo
                
Search
for
Updated Jun 04, 2009 by thomas.hug
Labels: Featured
MavenSeamHotdeployPluginUsage  
How to use the Seam hotdeploy Maven plugin

Seam Hotdeploy Maven Plugin Usage

The Seam Hotdeploy plugin allows you to build a Maven WAR project directly into a JBoss installation. This includes copying config files as well as XHTML/JSPs, and taking care about copying hot deployable classes into WEB-INF/dev instead of WEB-INF/classes.

Tested with:

Seam Project Setup

We propose following Maven setup for your Seam WAR project:

src
  |-- main
        |-- java       (Your entities, JSF classes, custom Identity component, ...)
        |-- hot        (Your hot deploy components)
        |-- resources  (Your config files, META-INF/persistence.xml, META-INF/components.xml, seam.properties etc.)
        |-- webapp     (Your XHTMLs, WEB-INF/faces-config.xml, WEB-INF/pages.xml, ...)
  |-- test
        |-- java       (Your test classes)
        |-- resources  (Your test config files, components.properties, seam.properties, ...)
        |-- bootstrap  (Embeddable JBoss config files)

UPDATE: For embedding the WAR inside an EAR, see further descriptions here.

Project POM Configuration

Add the following plugin repositories to your POM:

<pluginRepositories>
    <pluginRepository>
        <id>ctpjava</id>
        <name>CTP Public Repository</name>
        <url>http://ctpjava.googlecode.com/svn/trunk/repository</url>
    </pluginRepository>
    <pluginRepository>
        <id>repository.jboss.org</id>
        <name>JBoss Repository</name>
        <url>http://repository.jboss.org/maven2</url>
    </pluginRepository>
</pluginRepositories>

Use the build helper plugin to add the hot source folder to your Maven build, and integrate the CLI plugin for much more build convenience:

<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>build-helper-maven-plugin</artifactId>
    <executions>
        <execution>
            <id>add-source</id>
            <phase>generate-sources</phase>
            <goals>
                <goal>add-source</goal>
            </goals>
            <configuration>
                <sources>
                    <source>${basedir}/src/main/hot</source>
                </sources>
            </configuration>
        </execution>
    </executions>
</plugin>
<plugin>
    <groupId>org.twdata.maven</groupId>
    <artifactId>maven-cli-plugin</artifactId>
    <configuration>
        <userAliases>
            <hot>hotdeploy:exploded -o -Pdevelopment</hot>
            <cln>clean -o -Pdevelopment</cln>
        </userAliases>
    </configuration>
</plugin>

Add the additional test resource folders to your build:

<testResources>
    <testResource>
        <directory>src/test/resources</directory>
    </testResource>
    <testResource>
        <directory>src/test/bootstrap</directory>
    </testResource>
    <testResource>
        <directory>src/main/webapp</directory>
    </testResource>
</testResources>

Plugin Configuration

Now for the plugin configuration. Create a dedicated build profile in your POM. We will change the behavior of the clean plugin there as well:

<profile>
    <id>development</id>
    <build>
        <defaultGoal>hotdeploy:exploded</defaultGoal>
...

Add the following plugins to the profile build:

<plugin>
    <groupId>com.ctp.seam.maven</groupId>
    <artifactId>maven-hotdeploy-plugin</artifactId>
    <version>0.2.1</version>
    <configuration>
        <source>${java.source.version}</source>
        <target>${java.source.version}</target>
        <sourceDirectory>src/main/hot</sourceDirectory>
        <deployDirectory>
            ${directory.deploy.jboss}/${build.finalName}.${project.packaging}
        </deployDirectory>
    </configuration>
</plugin>
<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-clean-plugin</artifactId>
    <version>2.2</version>
    <configuration>
        <filesets>
            <fileset>
                <directory>${directory.deploy.jboss}</directory>
                <includes>
                    <include>**/${build.finalName}.${project.packaging}*</include>
                </includes>
            </fileset>
        </filesets>
    </configuration>
</plugin>

Add appropriate values in the POMs properties section. Values to replace are:

You can also overwrite the WAR file name if you want to get rid of the version number. Add this to your build config or to your development profile.

<finalName>${project.artifactId}</finalName>

For a complete POM example see the sample POM Wiki page.

Run the Plugin

On the command line, first type

mvn cli:execute-phase

which starts a 'Maven shell' from the CLI plugin, speeding up reexecutions. From here, start the build with the alias

maven2> hot

(which stands for mvn hotdeploy:exploded -P development). This will deploy your WAR file into the JBoss deploy folder. If you need to clean out your running application first, use

maven2> cln hot

If you have a multi-module project, make sure this is only run on the web module.


Comment by gjeudy, Apr 06, 2009

Hi Thomas,

Nice plugin it was working fine last week but it doesnt work anymore. When I do mvn clean hotdeploy:exploded it fails with: INFO? The plugin 'org.apache.maven.plugins:maven-hotdeploy-plugin' does not exist or no valid version could be found

I have to do the following command to bypass this error message:

mvn clean com.ctp.seam.maven:maven-hotdeploy-plugin:0.2.1:exploded

unfortunately property interpolation doesn't seem to work when calling the plugin that way.

A maven dev is telling me that such plugin setup is not recommended read below:

"The plugin groupId Maven is looking for is org.apache.maven.plugins. The groupId of your plugin must be something different.

I bet you're doing "mvn hotdeploy" and hoping it will just work. Try "mvn (groupId):maven-hotdeploy-plugin:(version):hotdeploy", assuming "hotdeploy" is the name of your Mojo. Also, you should not use the artifactId maven--plugin since that is reserved for official Maven plugins."

Comment by lucianooo, Jul 23, 2009

Hi,

I created a Seam project with the "JBoss Seam Maven Archetype - WAR only Project". Everything works great, and it seems that it is already configured with maven-hotdeploy-plugin and maven-cli-plugin.

If I run mvn cli:execute-phase and the hot I get this: maven2> hot INFO? Scanning for projects... INFO? Reactor build order: INFO? myproject? INFO? :: JBoss Configuration? INFO? :: Web Application? INFO? ------------------------------------------------------------------------ ERROR? BUILD FAILURE INFO? ------------------------------------------------------------------------ INFO? Invalid task 'hot': you must specify a valid lifecycle phase, or a goal in the format plugin:goal or pluginGroupI d:pluginArtifactId:pluginVersion:goal INFO? ------------------------------------------------------------------------ INFO? Trace org.apache.maven.BuildFailureException?: Invalid task 'hot': you must specify a valid lifecycle phase, or a goal in the f ormat plugin:goal or pluginGroupId:pluginArtifactId:pluginVersion:goal

at org.apache.maven.lifecycle.DefaultLifecycleExecutor?.getMojoDescriptor(DefaultLifecycleExecutor?.java:1787) at org.apache.maven.lifecycle.DefaultLifecycleExecutor?.segmentTaskListByAggregationNeeds(DefaultLifecycleExecuto?
r.java:446)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor?.execute(DefaultLifecycleExecutor?.java:176) at org.apache.maven.DefaultMaven?.doExecute(DefaultMaven?.java:356) at org.apache.maven.DefaultMaven?.execute(DefaultMaven?.java:137) at org.twdata.maven.cli.ExecutePhaseCliMojo?.executeCommand(ExecutePhaseCliMojo?.java:403) at org.twdata.maven.cli.ExecutePhaseCliMojo?.execute(ExecutePhaseCliMojo?.java:204) at org.apache.maven.plugin.DefaultPluginManager?.executeMojo(DefaultPluginManager?.java:483) at org.apache.maven.lifecycle.DefaultLifecycleExecutor?.executeGoals(DefaultLifecycleExecutor?.java:678) at org.apache.maven.lifecycle.DefaultLifecycleExecutor?.executeStandaloneGoal(DefaultLifecycleExecutor?.java:553) at org.apache.maven.lifecycle.DefaultLifecycleExecutor?.executeGoal(DefaultLifecycleExecutor?.java:523) at org.apache.maven.lifecycle.DefaultLifecycleExecutor?.executeGoalAndHandleFailures(DefaultLifecycleExecutor?.jav
a:371)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor?.executeTaskSegments(DefaultLifecycleExecutor?.java:268) at org.apache.maven.lifecycle.DefaultLifecycleExecutor?.execute(DefaultLifecycleExecutor?.java:181) at org.apache.maven.DefaultMaven?.doExecute(DefaultMaven?.java:356) at org.apache.maven.DefaultMaven?.execute(DefaultMaven?.java:137) at org.apache.maven.cli.MavenCli?.main(MavenCli?.java:362) at org.apache.maven.cli.compat.CompatibleMain?.main(CompatibleMain?.java:41) at sun.reflect.NativeMethodAccessorImpl?.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl?.invoke(NativeMethodAccessorImpl?.java:39) at sun.reflect.DelegatingMethodAccessorImpl?.invoke(DelegatingMethodAccessorImpl?.java:25) at java.lang.reflect.Method.invoke(Method.java:597) at org.codehaus.classworlds.Launcher.launchEnhanced(Launcher.java:315) at org.codehaus.classworlds.Launcher.launch(Launcher.java:255) at org.codehaus.classworlds.Launcher.mainWithExitCode(Launcher.java:430) at org.codehaus.classworlds.Launcher.main(Launcher.java:375)

If I go inside the web module and run the same thing, I get this:

maven2> hot INFO? NOTE: Maven is executing in offline mode. Any artifacts not already in your local repository will be inaccessible.

INFO? Scanning for projects... INFO? ------------------------------------------------------------------------ ERROR? BUILD ERROR INFO? ------------------------------------------------------------------------ INFO? Internal error in the plugin manager getting plugin 'com.ctp.seam.maven:maven-hotdeploy-plugin': Plugin 'com.ctp. seam.maven:maven-hotdeploy-plugin:0.3.1' has an invalid descriptor: 1) Plugin's descriptor contains the wrong group ID: org.twdata.maven 2) Plugin's descriptor contains the wrong artifact ID: maven-cli-plugin 3) Plugin's descriptor contains the wrong version: 0.6.4 INFO? ------------------------------------------------------------------------ INFO? Trace org.apache.maven.lifecycle.LifecycleExecutionException?: Internal error in the plugin manager getting plugin 'com.ctp.sea m.maven:maven-hotdeploy-plugin': Plugin 'com.ctp.seam.maven:maven-hotdeploy-plugin:0.3.1' has an invalid descriptor: 1) Plugin's descriptor contains the wrong group ID: org.twdata.maven 2) Plugin's descriptor contains the wrong artifact ID: maven-cli-plugin 3) Plugin's descriptor contains the wrong version: 0.6.4

at org.apache.maven.lifecycle.DefaultLifecycleExecutor?.verifyPlugin(DefaultLifecycleExecutor?.java:1543) at org.apache.maven.lifecycle.DefaultLifecycleExecutor?.getMojoDescriptor(DefaultLifecycleExecutor?.java:1744) at org.apache.maven.lifecycle.DefaultLifecycleExecutor?.segmentTaskListByAggregationNeeds(DefaultLifecycleExecuto?
r.java:446)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor?.execute(DefaultLifecycleExecutor?.java:176) at org.apache.maven.DefaultMaven?.doExecute(DefaultMaven?.java:356) at org.apache.maven.DefaultMaven?.execute(DefaultMaven?.java:137) at org.twdata.maven.cli.ExecutePhaseCliMojo?.executeCommand(ExecutePhaseCliMojo?.java:403) at org.twdata.maven.cli.ExecutePhaseCliMojo?.execute(ExecutePhaseCliMojo?.java:204) at org.apache.maven.plugin.DefaultPluginManager?.executeMojo(DefaultPluginManager?.java:483) at org.apache.maven.lifecycle.DefaultLifecycleExecutor?.executeGoals(DefaultLifecycleExecutor?.java:678) at org.apache.maven.lifecycle.DefaultLifecycleExecutor?.executeStandaloneGoal(DefaultLifecycleExecutor?.java:553) at org.apache.maven.lifecycle.DefaultLifecycleExecutor?.executeGoal(DefaultLifecycleExecutor?.java:523) at org.apache.maven.lifecycle.DefaultLifecycleExecutor?.executeGoalAndHandleFailures(DefaultLifecycleExecutor?.jav
a:371)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor?.executeTaskSegments(DefaultLifecycleExecutor?.java:268) at org.apache.maven.lifecycle.DefaultLifecycleExecutor?.execute(DefaultLifecycleExecutor?.java:181) at org.apache.maven.DefaultMaven?.doExecute(DefaultMaven?.java:356) at org.apache.maven.DefaultMaven?.execute(DefaultMaven?.java:137) at org.apache.maven.cli.MavenCli?.main(MavenCli?.java:362) at org.apache.maven.cli.compat.CompatibleMain?.main(CompatibleMain?.java:41) at sun.reflect.NativeMethodAccessorImpl?.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl?.invoke(NativeMethodAccessorImpl?.java:39) at sun.reflect.DelegatingMethodAccessorImpl?.invoke(DelegatingMethodAccessorImpl?.java:25) at java.lang.reflect.Method.invoke(Method.java:597) at org.codehaus.classworlds.Launcher.launchEnhanced(Launcher.java:315) at org.codehaus.classworlds.Launcher.launch(Launcher.java:255) at org.codehaus.classworlds.Launcher.mainWithExitCode(Launcher.java:430) at org.codehaus.classworlds.Launcher.main(Launcher.java:375)
Caused by: org.apache.maven.plugin.PluginManagerException?: Plugin 'com.ctp.seam.maven:maven-hotdeploy-plugin:0.3.1' has an invalid descriptor: 1) Plugin's descriptor contains the wrong group ID: org.twdata.maven 2) Plugin's descriptor contains the wrong artifact ID: maven-cli-plugin 3) Plugin's descriptor contains the wrong version: 0.6.4
at org.apache.maven.plugin.DefaultPluginManager?.addPlugin(DefaultPluginManager?.java:323) at org.apache.maven.plugin.DefaultPluginManager?.verifyVersionedPlugin(DefaultPluginManager?.java:217) at org.apache.maven.plugin.DefaultPluginManager?.verifyPlugin(DefaultPluginManager?.java:177) at org.apache.maven.lifecycle.DefaultLifecycleExecutor?.verifyPlugin(DefaultLifecycleExecutor?.java:1539) ... 26 more
INFO? ------------------------------------------------------------------------ INFO? Total time: < 1 second INFO? Finished at: Thu Jul 23 16:56:19 CDT 2009 INFO? Final Memory: 10M/127M INFO? ------------------------------------------------------------------------ ERROR? Failed to execute 'hotdeploy:exploded?' on 'myproject-webapp' INFO? Execution time: 125 ms

I am using maven 2.2.0 and JDK 1.6.0_12

Thank you,

Lucian

Comment by lucianooo, Jul 23, 2009

I upgraded to cli 0.6.6 and added the configuration of this plugin to the main pom file and it worked nice.

Thank you,

Lucian


Sign in to add a comment
Hosted by Google Code