JBoss Seam project setup with Maven — Part 2: EAR deployment
Tuesday, October 9th, 2007In a previous post, I discussed how to setup a Maven project for your Seam WAR application. However, most Seam developers are probably working on applications with EJB3 components to fully take advantage of the service infrastructure of the JBoss AS container. So, to complete this series, I setup a maven project for Seam EAR deployment. The project structure is as follows. The ejb module builds the JAR for EJB3 components; the war project build the web application; and the ear module builds the EAR application with necessary library JARs.
-
.
-
|-- pom.xml
-
|
-
|-- ear
-
| `-- pom.xml
-
|
-
|-- ejb
-
| |-- pom.xml
-
| |-- src
-
| `-- main
-
| |-- java
-
| | `-- com
-
| | `-- example
-
| | `-- ejb
-
| | |-- MyEnterpriseBeanImpl.java
-
| | `-- MyEnterpriseBean.java
-
| `-- resources
-
| |-- seam.properties
-
| `-- ejb-jar.xml
-
|
-
|-- war
-
|-- pom.xml
-
`-- src
-
`-- main
-
|-- java
-
| `-- com
-
| `-- example
-
| `-- SampleAction.java (and other Java source files)
-
|-- resources
-
| |-- META-INF
-
| | `-- persistence.xml
-
| |-- messages.properties
-
| `-- seam.properties
-
`-- webapp
-
|-- WEB-INF
-
| | -- components.xml
-
| | -- pages.xml
-
| | -- face-config.xml
-
| `-- web.xml
-
`-- hello.xhtml (and other web content, CSS, templates, and images)
The main pom.xml file defines the shared libraries required by all modules. It optionally uses the Seam parent POM to set the version numbers for the dependency JARs. Here is how it might look like:
-
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
-
-
<repositories>
-
<repository>
-
<id>jboss-snapshot</id>
-
<name>The JBoss maven repo</name>
-
<url>http://snapshots.jboss.org/maven2</url>
-
</repository>
-
</repositories>
-
<parent>
-
<groupId>org.jboss.seam</groupId>
-
<artifactId>root</artifactId>
-
<version>2.0.0-SNAPSHOT</version>
-
</parent>
-
-
<modelVersion>4.0.0</modelVersion>
-
<groupId>mystuff</groupId>
-
<artifactId>mystuff</artifactId>
-
<packaging>pom</packaging>
-
<version>1.0</version>
-
<name>mystuff</name>
-
<url>http://maven.apache.org</url>
-
-
<dependencies>
-
-
<dependency>
-
<groupId>log4j</groupId>
-
<artifactId>log4j</artifactId>
-
<scope>provided</scope>
-
</dependency>
-
-
<dependency>
-
<groupId>junit</groupId>
-
<artifactId>junit</artifactId>
-
<scope>test</scope>
-
</dependency>
-
-
</dependencies>
-
-
<modules>
-
<module>ejb</module>
-
<module>war</module>
-
<module>ear</module>
-
</modules>
-
-
<build>
-
<plugins>
-
<plugin>
-
<groupId>org.apache.maven.plugins</groupId>
-
<artifactId>maven-compiler-plugin</artifactId>
-
<configuration>
-
<source>1.5</source>
-
<target>1.5</target>
-
</configuration>
-
</plugin>
-
</plugins>
-
</build>
-
</project>
The ejb/pom.xml file defines the dependencies for the EJB3 module. Everything here is in the provided scope -- unless testing-specific libraries, which are in the test scope.
-
<project>
-
-
<parent>
-
<artifactId>mystuff</artifactId>
-
<groupId>mystuff</groupId>
-
<version>1.0</version>
-
</parent>
-
-
<modelVersion>4.0.0</modelVersion>
-
<groupId>mystuff</groupId>
-
<artifactId>ejb</artifactId>
-
<name>mystuff - ejb</name>
-
<version>1.0</version>
-
<url>http://maven.apache.org</url>
-
-
<build>
-
<finalName>ejb</finalName>
-
</build>
-
-
<dependencies>
-
-
<dependency>
-
<groupId>org.hibernate</groupId>
-
<artifactId>hibernate</artifactId>
-
<scope>provided</scope>
-
</dependency>
-
-
<dependency>
-
<groupId>org.hibernate</groupId>
-
<artifactId>hibernate-entitymanager</artifactId>
-
<scope>provided</scope>
-
</dependency>
-
-
<dependency>
-
<groupId>org.hibernate</groupId>
-
<artifactId>hibernate-annotations</artifactId>
-
<scope>provided</scope>
-
</dependency>
-
-
<dependency>
-
<groupId>org.hibernate</groupId>
-
<artifactId>hibernate-validator</artifactId>
-
<scope>provided</scope>
-
</dependency>
-
-
<dependency>
-
<groupId>org.jboss.seam</groupId>
-
<artifactId>jboss-seam</artifactId>
-
<scope>provided</scope>
-
</dependency>
-
-
<dependency>
-
<groupId>javax.ejb</groupId>
-
<artifactId>ejb-api</artifactId>
-
<scope>provided</scope>
-
</dependency>
-
-
<dependency>
-
<groupId>hsqldb</groupId>
-
<artifactId>hsqldb</artifactId>
-
<version>1.7.2</version>
-
<scope>test</scope>
-
</dependency>
-
-
</dependencies>
-
-
</project>
The war/pom.xml file defines the dependencies for the WAR module. It depends on the ejb module.
-
<?xml version="1.0" encoding="UTF-8"?>
-
<project>
-
<parent>
-
<artifactId>mystuff</artifactId>
-
<groupId>mystuff</groupId>
-
<version>1.0</version>
-
</parent>
-
<modelVersion>4.0.0</modelVersion>
-
-
<groupId>mystuff</groupId>
-
<artifactId>war</artifactId>
-
<name>mystuff - web</name>
-
<version>1.0</version>
-
<packaging>war</packaging>
-
<url>http://maven.apache.org</url>
-
-
<build>
-
<finalName>war</finalName>
-
</build>
-
-
<dependencies>
-
-
<dependency>
-
<groupId>mystuff</groupId>
-
<artifactId>ejb</artifactId>
-
<version>1.0</version>
-
<scope>provided</scope>
-
<type>ejb</type>
-
</dependency>
-
-
<!-- The following 4 dependencies are included in the WEB-INF/lib of the war -->
-
-
<dependency>
-
<groupId>org.jboss.seam</groupId>
-
<artifactId>jboss-seam-ui</artifactId>
-
</dependency>
-
-
<dependency>
-
<groupId>org.jboss.seam</groupId>
-
<artifactId>jboss-seam-debug</artifactId>
-
</dependency>
-
-
<dependency>
-
<groupId>com.sun.facelets</groupId>
-
<artifactId>jsf-facelets</artifactId>
-
</dependency>
-
-
<dependency>
-
<groupId>org.richfaces.ui</groupId>
-
<artifactId>richfaces-ui</artifactId>
-
</dependency>
-
-
<!-- The "provided" dependencies are only need for compilation -->
-
-
<dependency>
-
<groupId>javax.servlet</groupId>
-
<artifactId>servlet-api</artifactId>
-
<scope>provided</scope>
-
</dependency>
-
-
<dependency>
-
<groupId>org.jboss.seam</groupId>
-
<artifactId>jboss-seam</artifactId>
-
<scope>provided</scope>
-
</dependency>
-
-
<dependency>
-
<groupId>javax.faces</groupId>
-
<artifactId>jsf-api</artifactId>
-
<scope>provided</scope>
-
</dependency>
-
-
<dependency>
-
<groupId>javax.faces</groupId>
-
<artifactId>jsf-impl</artifactId>
-
<scope>provided</scope>
-
</dependency>
-
-
<dependency>
-
<groupId>org.hibernate</groupId>
-
<artifactId>hibernate-validator</artifactId>
-
<scope>provided</scope>
-
</dependency>
-
-
</dependencies>
-
</project>
The ear/pom.xml file defines how the EAR application is assembled. You need to declare any JARs you want to include in the EAR as dependencies. I also used a JBoss-specific element to setup the class loader repository for the application. It is often needed in JPA applications. Yes, it is verbose -- if you have a better idea, let me know.
-
<project>
-
-
<parent>
-
<artifactId>mystuff</artifactId>
-
<groupId>mystuff</groupId>
-
<version>1.0</version>
-
</parent>
-
-
<modelVersion>4.0.0</modelVersion>
-
<groupId>mystuff</groupId>
-
<artifactId>ear</artifactId>
-
<name>mystuff - ear</name>
-
<packaging>ear</packaging>
-
<version>1.0</version>
-
<url>http://maven.apache.org</url>
-
-
<dependencies>
-
-
<dependency>
-
<groupId>mystuff</groupId>
-
<artifactId>ejb</artifactId>
-
<version>1.0</version>
-
<type>ejb</type>
-
</dependency>
-
-
<dependency>
-
<groupId>mystuff</groupId>
-
<artifactId>war</artifactId>
-
<version>1.0</version>
-
<type>war</type>
-
</dependency>
-
-
<dependency>
-
<groupId>org.jboss.seam</groupId>
-
<artifactId>jboss-seam</artifactId>
-
<type>ejb</type>
-
</dependency>
-
-
<dependency>
-
<groupId>org.jboss.seam</groupId>
-
<artifactId>jboss-el</artifactId>
-
<exclusions>
-
<exclusion>
-
<groupId>javax.el</groupId>
-
<artifactId>el-api</artifactId>
-
</exclusion>
-
</exclusions>
-
<type>jar</type>
-
</dependency>
-
-
<dependency>
-
<groupId>commons-beanutils</groupId>
-
<artifactId>commons-beanutils</artifactId>
-
<exclusions>
-
<exclusion>
-
<groupId>commons-logging</groupId>
-
<artifactId>commons-logging</artifactId>
-
</exclusion>
-
</exclusions>
-
<type>jar</type>
-
</dependency>
-
-
</dependencies>
-
-
<build>
-
<plugins>