如何在 EAR 中正确使用 OmniFaces [英] How to correctly use OmniFaces in an EAR

查看:19
本文介绍了如何在 EAR 中正确使用 OmniFaces的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在我的 Jave EE 7 应用程序中使用 OmniFaces 1.7.我的应用程序是一个包含 JAR 的 EAR 和一个 skinny WAR.我的一些 JAR 依赖于 OmniFaces,因此 OmniFaces 工件必须在 EAR 中,而不是在 WAR 中的 WEB-INF/lib 中.

I want to use OmniFaces 1.7 in my Jave EE 7 application. My application is an EAR that contains JARs and a skinny WAR. Some of my JARs have a dependency to OmniFaces, so the OmniFaces artifact must be in the EAR but not in WEB-INF/lib in the WAR.

这是我的 EAR 的样子:

Here is how my EAR looks like:

EAR
 +-- lib
 |    +-- [some 3rd party JARs]
 |    `-- omnifaces.jar
 +-- myEJBs.jar
 `-- myWAR.war

当我这样说时,OmniFaces 转换器(例如 GenericEnumConverter) 未在 JSF 中注册,因此无法使用.其原因在此处此处.基本上根据 JSF 2.0 规范(部分 11.5.1 要求扫描类以获取注释),只扫描 WARs WEB-INF/lib 目录.

When I put it this way, OmniFaces converters (like GenericEnumConverter) are not registered with JSF and won't work. The reason for this is discussed here and here. Basically according to the JSF 2.0 Spec (section 11.5.1 Requirements for scanning of classes for annotations), only the WARs WEB-INF/lib directory is scanned.

所以我的问题是:我应该如何在我的应用程序中包含 OmniFaces?

将它包含两次(在 EAR/lib 和 WARs WEB-INF/lib 中)可能可行,但感觉很笨拙.前段时间我用 RichFaces 4.3.5(同样的问题)尝试过,但没有奏效,但导致 IllegalArgumentException: duplicate key: class javax.faces.convert.ByteConverter.

Including it twice (in EAR/lib and WARs WEB-INF/lib) could possibly work but feels clumsy. I tried it some time ago with RichFaces 4.3.5 (same problem) which didn't work but led to IllegalArgumentException: duplicate key: class javax.faces.convert.ByteConverter.

推荐答案

OmniFaces 是一个 JSF 实用程序库,依赖于 JSF、EL 和 Servlet API,这些 API 通常仅在 WAR 中可用,而不在 EAR 中可用.更重要的是,您的 EJB(一般的业务服务)不应依赖于特定的前端 API,例如 JSF、EL 和 Servlet API.这会使它们无法在其他前端(例如 JAX-RS、Spring MVC 等)上重用.

OmniFaces is a JSF utility library with dependencies on JSF, EL and Servlet APIs, which are normally only available inside a WAR, not an EAR. Even more, your EJBs (business services in general) are not supposed to have any dependencies on specific front-end APIs such as JSF, EL and Servlet APIs. It would make them unreusable on other front-ends such as JAX-RS, Spring MVC, etc.

您需要将 JSF 实用程序和组件库(例如 OmniFaces 和 PrimeFaces)放在 WAR 中,而不是放在 EAR 中.另请参阅 OmniFaces 主页的安装部分:

You need to put JSF utility and component libraries such as OmniFaces and PrimeFaces in WAR, not in EAR. See also Installation section of OmniFaces homepage:

OmniFaces 被设计为一个 WAR 库(Web 片段库),因此不能放置在 WAR 自己的 /WEB-INF/lib 之外的 webapp 运行时类路径中的其他位置,例如 EAR 的 /lib 甚至服务器或 JRE 自己的 /lib.当 OmniFaces JAR 文件以这种方式放错位置时,Web 应用程序将无法找到 OmniFaces 捆绑的 JSF/CDI 注释类,并在部署或运行​​时抛出与此相关的异常.要解决它,请将 OmniFaces 放回 WAR 的 /WEB-INF/lib 中.

OmniFaces is designed as a WAR library (web fragment library) and therefore can't be placed elsewhere in the webapp's runtime classpath outside WAR's own /WEB-INF/lib, such as EAR's /lib or even server's or JRE's own /lib. When OmniFaces JAR file is misplaced this way, then the webapp will be unable to find OmniFaces-bundled JSF/CDI annotated classes and throw exceptions related to this during deploy or runtime. To solve it, put back OmniFaces in WAR's /WEB-INF/lib.

另见:

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