问题描述
我想在我的Java EE 6(Jboss AS 7.1.1Final)应用程序中使用PrimeFaces具有以下结构:
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
然而,在部署到JBoss AS 7时,我遇到了几个例外情况,例如:
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)
对于EAR的pom。 xml,我正在使用PrimeFaces的Maven依赖:
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>
然而,当我将依赖项放入一个WAR的pom.xml中时,它可以工作,但我想要在多个WAR之间共享primefaces库。
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.
我已经google了很多但是没有找到任何解决方案。谢谢你的任何建议。
I've googled a lot but have not found any solution. Thank you for any advice.
推荐答案
你不能。 Webapp库不属于 EAR / lib
,但在 WAR / WEB-INF / lib
中。 EAR / lib
永远不会被用作EAR所有WAR项目的共享库。这仅适用于EAR的所有EJB项目(业务服务)。
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.
PrimeFaces上的 LinkageError
- 您所面临的特定类是由于(默认)特定于webapp的库(如JSF API / impl)不可用于 EAR / lib
所使用的类加载器。这会导致 EAR / lib
中的所有库在 WAR / WEB-INF / lib
中具有(虚拟)依赖关系失败,类加载错误,如 LinkageError
。
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
.
如果你真的需要一个所有WAR的共享库项目,那么你最好的选择是将库放在Java EE容器本身(就像默认情况下已经为JSF API / impl库完成的那样)。在JBoss的情况下,这被称为模块。但是我不建议这样做,因为这使得webapp不能跨容器移植,而不需要通过serveradmin专门配置容器。只需为每个webapp提供一组自己的webapp库。
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.
这篇关于无法将PrimeFaces添加为EAR的库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!