This page covers how to use Seam 3 and Weld with EAR packaging, specifically for JBoss AS 6 deployment.
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:
- For Java Enterprise 6 Containers (like JBoss AS 6):
- You can leave the
<version>out if you've imported
- You can leave the
- An easy way to get all the Java Enterprise 6 Dependencies:
META-INFin any EJB jars.
WEB-INFdirectory in any WAR files.
faces-config.xmlto the WAR file.
- Add the following to
Add the dependencies to your parent
pom.xml, for example:
- Leave the versions off if you've already imported
Bugs and Workarounds
Workaround 1 - Add the Servlet and Filter declarations to
The basic idea of this workaround is:
- Deploy the Seam modules as 'java modules' in the EAR.
- Workaround some discovery issues by adding
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
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
web-fragment.xml elements into
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
Workaround 2 - Deploy Seam Modules in
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
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