I'd like to use PrimeFaces in my Java EE 6 (Jboss AS 7.1.1Final) application with this structure:
EAR
|- lib/
| |- primefaces-4.0.jar
|
|- ejb-module.jar
|- webbapp1.war
|- webapp2.war
However, when deploying to JBoss AS 7, I'm getting several exceptions such as:
java.lang.LinkageError: Failed to link org/primefaces/context/PrimeFacesContextFactory
(Please see the full stack trace here on PasteBin)
For EAR's pom.xml, I'm using this Maven dependency for PrimeFaces:
<dependency>
<groupId>org.primefaces</groupId>
<artifactId>primefaces</artifactId>
<version>4.0</version>
<type>jar</type>
</dependency>
However, when I put the dependency into pom.xml of one WAR, it works, but I want to share the primefaces library between multiple WARs.
I've googled a lot but have not found any solution. Thank you for any advice.
You cannot. Webapp libraries do not belong in
EAR/lib
, but inWAR/WEB-INF/lib
. TheEAR/lib
is never intented as a "shared library" for all WAR projects of the EAR. It's that only for all EJB projects (the business services) of the EAR.The
LinkageError
on a PrimeFaces-specific class which you're facing is caused because the (default) webapp-specific libraries like JSF API/impl are not available to the classloader as used byEAR/lib
. This causes all libraries in theEAR/lib
which have a (virtual) dependency inWAR/WEB-INF/lib
to fail with class loading errors likeLinkageError
.If you really really need a "shared library" for all WAR projects, then your best bet is putting the library in Java EE container itself (like as by default already done for JSF API/impl libraries). In case of JBoss, that's called a "module". I however wouldn't recommend that as that makes the webapp unportable across containers without specifically configuring the container by the serveradmin. Just give each webapp its own set of webapp libraries.