Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.0k views
in Technique[技术] by (71.8m points)

jsf 2 - How to correctly use OmniFaces in an EAR

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.

Here is how my EAR looks like:

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

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.

So my question is: how should I include OmniFaces in my application?

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.

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 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.

See also:


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...