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

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

问题描述

我想在我的Jave EE 7应用程序中使用 OmniFaces 1.7.我的应用程序是一个EAR,其中包含JAR和瘦的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之外的Web应用程序运行时类路径中的其他位置,例如EAR的/lib甚至服务器的或JRE自己的/lib .当OmniFaces JAR文件以这种方式放错位置时,Webapp将无法找到捆绑了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天全站免登陆