Overview
This page covers how to use Seam 3 and Weld with EAR packaging, specifically for JBoss AS 6 deployment.
| IMPORTANT Most of the Seam 3 examples use WAR packaging, as EJB 3.1 supports EJBs inside a WAR. If you can deal with the restrictions, it is probably best to use WAR packaging. Use EAR packaging if you need the features of EAR deployment. |
General CDI Application Setup
The simplest way get all the dependency management (version declarations) for a Seam 3 application is to add this to your parent POM:
Add the Weld/CDI Maven dependencies:
- For Java Enterprise 6 Containers (like JBoss AS 6):
- You can leave the
<version>out if you've importedseam-bom.
- You can leave the
- An easy way to get all the Java Enterprise 6 Dependencies:
Add beans.xml to:
- The
META-INFin any EJB jars. - The
WEB-INFdirectory in any WAR files.
JSF/Facelets:
- Add
WEB-INF/faces-config.xmlto the WAR file. - Add the following to
WEB-INF/web.xml:
Seam Modules
Add the dependencies to your parent pom.xml, for example:
- Leave the versions off if you've already imported
seam-bom
|
Bugs and Workarounds
Workaround 1 - Add the Servlet and Filter declarations to web.xml
The basic idea of this workaround is:
- Deploy the Seam modules as 'java modules' in the EAR.
- Workaround some discovery issues by adding
web-fragment.xmlinformation toweb.xml.
Add the Seam Modules to the EAR
Add the seam modules to your application.xml via the maven-ear-plugin:
- Use the
<unpackTypes>setting to prevent the plugin from making a 'russian doll' ear. - IMPORTANT: Note that the dependencies that are not part of the application have
<includeInApplicationXml>true</includeInApplicationXml>. This is because the maven-ear-plugin doesn't include "third party" modules by default. See 'including a third party library in application.xml'
Don't put the Seam Modules in WEB-INF/lib
You'll also have to make sure that your WAR file does't include the seam modules in WEB-INF/lib. If you forget to do this, then Weld will probably try to deploy some components twice. The simple way to do this is to explicitly declare the dependencies in the WAR pom.xml file as <scope>provided</scope>:
Copy-paste web-fragment.xml elements into web.xml
Unfortunately, the nifty automatic inclusion of META-INF/web-fragment.xml won't work when seam-servlet.jar is not deployed in WEB-INF/lib. You'll need to copy the relevant content from META-INF/web-fragment.xml into your web.xml file:
Workaround 2 - Deploy Seam Modules in WEB-INF/lib
What about putting the Seam Modules only in WEB-INF/lib, with the WAR still inside the EAR? The basics of this workaround are:
- Deploy the seam modules in
WEB-INF/lib. Do not deploy the Seam modules as EAR-level 'Java Modules'. - Work around EAR classloader problems.
Basically this is using the same structure as a standalone WAR deployment. The CDI/Weld classes are provided by the container and the Seam Modules are in WEB-INF/lib. Unfortunately it doesn't work:
Presumably this is a classloader issue, and it can be avoided by disabling WarClassLoaderDeployer.
Other Reported Workarounds (that didn't work for me)
Some JBoss AS users have reported that useJBossWebClassLoader is also a way to workaround the EAR classloader issue. Note that there are two different approaches listed. The second approach - Adding WEB-INF/jboss-classloading.xml - Didn't work. Weld failed to initialize with a ClassNotFoundException.