Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Having trouble adding PrimeFaces as EAR's library

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.

like image 753
xwinus Avatar asked Feb 15 '23 19:02

xwinus


1 Answers

You cannot. Webapp libraries do not belong in EAR/lib, but in WAR/WEB-INF/lib. The EAR/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 by EAR/lib. This causes all libraries in the EAR/lib which have a (virtual) dependency in WAR/WEB-INF/lib to fail with class loading errors like LinkageError.

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.

like image 66
BalusC Avatar answered Feb 22 '23 21:02

BalusC