3

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.

Community
  • 1
  • 1
Martin Höller
  • 2,714
  • 26
  • 44
  • At [OmniFaces' known issues page](https://code.google.com/p/omnifaces/wiki/KnownIssuesCDI) is stated: "Also noted should be that OmniFaces can simply not be included as an EAR library due to dependencies which are typically only available inside the WAR, like JSF, Servlet and EL." But what if I want to use classes like `org.omnifaces.config.BeanManager` in my EJBs? – Martin Höller Feb 26 '14 at 16:12
  • After a [discussion](http://maven.40175.n5.nabble.com/Are-skinny-WARs-still-recommended-td5786626.html) on the maven-users list I think OmniFaces' classes like BeanManager or Utils should currently not be used from classes outside the WAR. A solution could be to split OmniFaces in two separate JARs: a true JSF Component Library and a common library usable everywhere. – Martin Höller Mar 03 '14 at 08:38

1 Answers1

4

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:

Community
  • 1
  • 1
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • Just for the records: I only had a dependency to OmniFaces' `BeanManager` class (as discussed on the [issue tracker](https://code.google.com/p/omnifaces/issues/detail?id=313)). And using CDI in EJBs is a valid use-case. But I ended up with the solution you suggested to put OmniFaces in the WAR. Thx. – Martin Höller Jun 10 '14 at 07:06