Do I need jsf-api or jsf-impl or both to start using JSF? Why are they not merged?

后端 未结 1 826
梦毁少年i
梦毁少年i 2020-12-11 05:25

I have started studying JSF and I would like to know what is the JAR to include within our classpath to start using JSF. Is it jsf-api or jsf-impl?

相关标签:
1条回答
  • 2020-12-11 05:34

    I'll assume that you're not using a real Java EE application server like WildFly, TomEE, GlassFish, etc, but a barebones JSP/Servlet container like Tomcat which indeed doesn't ship with JSF out the box and you thus had to manually install it. Otherwise, all this fuss with JARs is unnecessary.


    Is it jsf-api or jsf-impl? Or we have to include both?

    You need both. The jsf-api.jar contains the API, which exist of almost only abstract classes and interfaces. It are the javax.faces.* types which you are importing and using in your code. The jsf-impl.jar contains the implementation, which exist of the real hard working code. The implementation is internally loaded via factories in API. It are the com.sun.faces.* classes which you are not supposed to import and use directly in your code. If you do, then you wouldn't be able to switch to a different JSF implementation, such as MyFaces.


    And if it is both then why they are not merged?

    There exist a merged JAR, the javax.faces.jar. You can pick this one instead of the two loose JARs. Just navigate to the Download section in Mojarra homepage to find the link to Maven repository with javax.faces.jar files. Currently latest Mojarra version is 2.2.11, so pick the javax.faces-2.2.11.jar.

    See also:

    • Our JSF wiki page
    • JSF implementations and component libraries
    • Difference between Mojarra and MyFaces
    • In simplest terms, what is a factory?
    0 讨论(0)
提交回复
热议问题