将 PrimeFaces 添加为 EAR 的库时遇到问题 [英] Having trouble adding PrimeFaces as EAR's library

查看:17
本文介绍了将 PrimeFaces 添加为 EAR 的库时遇到问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在具有以下结构的 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 

(请在 PasteBin 上查看完整的堆栈跟踪 此处)

(Please see the full stack trace here on PasteBin)

对于 EAR 的 pom.xml,我将这个 Maven 依赖用于 PrimeFaces:

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.

我在谷歌上搜索了很多,但没有找到任何解决方案.感谢您的任何建议.

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 是因为 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 无法跨容器移植,而无需由服务器管理员专门配置容器.只需为每个 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 的库时遇到问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆