JSF – primefaces cannot be added as a library for ear

I want to use primefaces in my Java EE 6 (JBoss as 7.1.1final) application, which has the following structure:

EAR
|- lib/
|    |- primefaces-4.0.jar
|
|- ejb-module.jar
|- webbapp1.war
|- webapp2.war

However, when deploying to JBoss as 7, I encountered several exceptions, such as:

java.lang.LinkageError: Failed to link org/primefaces/context/PrimeFacesContextFactory

(see full stack trace here on Pastebin)

POM for ear XML, I'm using the Maven dependency of primefaces:

<dependency>
    <groupId>org.primefaces</groupId>
    <artifactId>primefaces</artifactId>
    <version>4.0</version>
    <type>jar</type>
</dependency>

But when I put dependencies into a war's POM XML, it works, but I want to share the primefaces Library among multiple wars

I've googled a lot, but I haven't found any solution Thank you for any advice

Solution

You can't The webapp library does not belong to ear / lib, but belongs to war / WEB-INF / lib Ear / lib has never been used as a "shared library" for all war projects in ear It only applies to all EJB projects (business services) in ear

The linkageerror on the primefaces specific class you are facing is because (by default) webapp specific libraries (such as JSF API / impl) are not available for class loaders used by ear / lib This will cause all libraries in ear / lib that have (virtual) dependencies with war / WEB-INF / lib to fail due to class loading errors (such as linkageerror)

If you really need a "shared library" for all war projects, the best way is to put the library in the Java EE container itself (as already done for the JSF API / impl library by default) In the case of JBoss, this is called a "module" But I don't recommend this because it makes webapp unable to migrate between containers without configuring containers through serveradmin Just provide each webapp with its own set of webapp libraries

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>