Deploying a J2EE Application
You have already learned how to deploy EJBs and WARs into a container individually. Deploying EARs follows the same principle. In this example, you’ll deploy the DayTrader EAR into Geronimo. Geronimo is somewhat special among J2EE containers in that deploying requires calling the Deployer tool with a deployment plan.
A plan is an XML file containing configuration information such as how to map CMP entity beans to a specific database, how to map J2EE resources in the container, etc. Like any other container, Geronimo also supports having this deployment descriptor located within the J2EE archives you are deploying.
However, it is recommended that you use an external plan file so that the deployment configuration is independent from the archives getting deployed, enabling the Geronimo plan to be modified to suit the deployment environment.
Note: The DayTrader application does not deploy correctly when using the JDK 5 or newer. You’ll need to use the JDK 1.4 for this section and the following.
To get started, store the deployment plan in ear/src/main/deployment/geronimo/plan.xml, as shown below.

Figure 4-12: Directory structure of the ear module showing the Geronimo deployment plan
How do you perform the deployment with Maven? One option would be to use Cargo as demonstrated earlier in the chapter. You would need the following pom.xml configuration snippet:
<plugin>
<groupId>org.codehaus.cargo</groupId>
<artifactId>cargo-maven2-plugin</artifactId>
<configuration>
<container>
<containerId>geronimo1x</containerId>
<zipUrlInstaller>
<url>http://www.apache.org/dist/geronimo/1.0/
geronimo-tomcat-j2ee-1.0.zip</url>
<installDir>${installDir}</installDir>
</zipUrlInstaller>
</container>
<deployer>
<deployables>
<deployable>
<properties>
<plan>${basedir}/src/main/deployment/geronimo/plan.xml</plan>
</properties>
</deployable>
</deployables>
</deployer>
</configuration>
</plugin>
However, in this section you’ll learn how to use the Maven Exec plugin. This plugin can execute any process. You’ll use it to run the Geronimo Deployer tool to deploy your EAR into a running Geronimo container. Even though it’s recommended to use a specific plugin like the Cargo plugin (as described in 4.13 Testing J2EE Applications), learning how to use the Exec plugin is useful in situations where you want to do something slightly different, or when Cargo doesn’t support the container you want to deploy into. Modify the ear/pom.xml to configure the Exec plugin:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<configuration>
<executable>java</executable>
<arguments>
<argument>-jar</argument>
<argument>${geronimo.home}/bin/deployer.jar</argument>
<argument>--user</argument>
<argument>system</argument>
<argument>--password</argument>
<argument>manager</argument>
<argument>deploy</argument>
<argument>
${project.build.directory}/${project.build.finalName}.ear
</argument>
<argument>
${basedir}/src/main/deployment/geronimo/plan.xml
</argument>
</arguments>
</configuration>
</plugin>
You may have noticed that you’re using a geronimo.home property that has not been defined anywhere. As you’ve seen in the EJB and WAR deployment sections above and in previous chapters it’s possible to create properties that are defined either in a properties section of the POM or in a Profile. As the location where Geronimo is installed varies depending on the user, put the following profile in a profiles.xml or settings.xml file:
<profiles>
<profile>
<id>vmassol</id>
<properties>
<geronimo.home>c:/apps/geronimo-1.0-tomcat</geronimo.home>
</properties>
</profile>
</profiles>
At execution time, the Exec plugin will transform the executable and arguments elements above into the following command line:
java -jar c:/apps/geronimo-1.0-tomcat/bin/deployer.jar
–user system –password manager deploy C:\dev\m2book\code\j2ee\daytrader\ear\target/daytrader-ear-1.0.ear
C:\dev\m2book\code\j2ee\daytrader\ear/src/main/deployment/geronimo/plan.xml
First, start your pre-installed version of Geronimo and run mvn exec:exec:
C:\dev\m2book\code\j2ee\daytrader\ear>mvn exec:exec
[...]
[INFO] [exec:exec]
[INFO] Deployed Trade
[INFO]
[INFO] `-> daytrader-web-1.0-SNAPSHOT.war
[INFO]
[INFO] `-> daytrader-ejb-1.0-SNAPSHOT.jar
[INFO]
[INFO] `-> daytrader-streamer-1.0-SNAPSHOT.jar
[INFO]
[INFO] `-> daytrader-wsappclient-1.0-SNAPSHOT.jar
[INFO]
[INFO] `-> TradeDataSource
[INFO]
[INFO] `-> TradeJMS
You can now access the DayTrader application by opening your browser to http://localhost:8080/daytrader/.
You will need to make sure that the DayTrader application is not already deployed before running the exec:exec goal or it will fail. Since Geronimo 1.0 comes with the DayTrader application bundled, you should first stop it, by creating a new execution of the Exec plugin or run the following:
C:\apps\geronimo-1.0-tomcat\bin>deploy stop
geronimo/daytrader-derby-tomcat/1.0/car
If you need to undeploy the DayTrader version that you’ve built above you’ll use the “Trade” identifier instead:
C:\apps\geronimo-1.0-tomcat\bin>deploy undeploy Trade

