JBoss Seam: Maven Archetype for JBoss Seam

Mar 20 2009

JBoss Seam is a powerful new application framework to build next generation Web 2.0 applications by unifying and integrating popular service oriented architecture (SOA) technologies like Asynchronous JavaScript and XML(AJAX), Java Server Faces(JSF), Enterprise Java Beans(EJB3), Java Portlets and Business Process Management(BPM) and workflow.” (JBoss Seam)

Seam, by default, is set up to compile, package, and deploy using Ant. Many developers, however, would like to use Maven 2 to build their application. In order to make the process of configuring Maven to correctly build a Seam project easier, Lunar Logic has created a Maven Archetype that will create an empty Seam project that compiles and packages using Maven.

Obtaining the Archetype

Add the following entry to your ~/.m2/settings.xml file


<settings>
...
<profiles>
...
<profile>
<id>lunarlogic-repository-profile</id>
<repositories>
<repository>
<id>lunarlogic</id>
<url>http://labs.lunarlogic.com/proximity/repository/lunarlogic</url>
</repository>
</repositories>
</profile>
...
</profiles>
...
<activeProfiles>
...
<activeProfile>lunarlogic-repository-profile</activeProfile>
...
</activeProfiles>
...
</settings>

Using the Archetype

  1. To create a project, issue the following command from the command line:

    mvn archetype:create -DarchetypeGroupId=com.lunarlogic.maven.archetypes -DarchetypeArtifactId=maven-archetype-jee-seam -DarchetypeVersion=1.0.1 -DgroupId=<myAppGroupId> -DartifactId=<myAppArtifactId>
  2. Open README.txt in your project and follow the instructions to finish configuring your application.
  3. To package up your Seam application as an EAR, issue the following command from the command line:
    mvn clean install
    The resulting EAR will be in the ear/target directory.

Directory Structure


my-app
|-- pom.xml
|-- README.txt
|-- ear
| |-- pom.xml
| |-- myApp-ds.xml
| `-- src
| `-- main
| `-- resources
| `-- META-INF
| `-- jboss-app.xml
|-- ejb
| |-- pom.xml
| `-- src
| |-- main
| | |-- java
| | | `-- App.java
| | `-- resources
| | |-- seam.properties
| | `-- META-INF
| | |-- ejb-jar.xml
| | `-- persistence.xml
| `-- test
| `-- java
| `-- AppTest.java
|-- src
| `-- main
| `-- resources
`-- web
|-- pom.xml
`-- src
`-- main
|-- resources
| `-- localization
| |-- application.properties
| `-- hello
| `-- helloWorld.properties
`-- webapp
|-- helloWorld.xhtml
|-- common
| |-- footer.xhtml
| `-- layout.xhtml
|-- css
| `-- app.css
`-- WEB-INF
|-- components.xml
|-- faces-config.xml
|-- pages.xml
|-- web.xml
`-- lib
`-- tomahawk.taglib.xml

The project is split up into three separate submodules: ear, ejb, and web. The EJB module contains all of the java code, including Seam actions and EJB 3.0 entity beans. The WEB module contains all of the JSF pages, web application configuration files, and static web content such as images and css. The EAR module contains the enterprise application deployment files.

When you package the project from the root directory, the EJB module is packaged into a JAR, the WEB module is packaged into a WAR, and then the EAR module packages the JAR and the WAR into an EAR along with the application deployment files.

Note: All of the java code has to be in one jar file because JBoss AS 4.0.4 does not implement the entire EJB 3.0 spec. JBoss AS 4.0.4 only allows the specification of a persistence unit at the JAR level, but not at the WAR or the EAR level.

- Phillip Singer, Senior Developer