Having trouble adding PrimeFaces as EAR's library

橙三吉。 提交于 2019-12-12 15:51:54

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/19766234/having-trouble-adding-primefaces-as-ears-library

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!