We have a library that contains small additions to functionality provided by JSF (things like additional ResourceHandlers).
As it uses JSF classes (from javax.faces.*
packages), it naturally must depend on the JSF API. The library is packaged as a Maven project, and depends on com.sun.faces:jsf-api
.
This works fine for compiling, and for use in projects that use Mojarra. However, if we include the library in a JSF application that uses MyFaces, we get errors, as described in Exception: could not find Factory: javax.faces.context.FacesContextFactory .
Apparently, if an application uses MyFaces, it must use myfaces-api.jar and myfaces-impl.jar (or the corresponding Maven deps), and not jsf-api.jar or jsf-impl.jar.
This leaves me a bit confused.
- Why do Mojarra and MyFaces use different API jars? Both implement the same API (JSF), so shouldn't they use the same API jars?
- I thought the whole point of having seperate "api" and "impl" jars was that only the "impl" part has to be switched to use a different implementation. Did I misunderstand something?
- More concretely: What is the right Maven dependency for a library that should only depend on the JSF API? Right now, we depend on jsf-api, and projects that use MyFaces must use
<exclusions>
to throw out jsf-api and include myfaces-api. That works, but surely there is a better way?