Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

jar

jsf

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? Or we have to include both? And if it is both then why they are not merged?

like image 732
Bharat Bisht Avatar asked Jul 17 '15 08:07

Bharat Bisht


1 Answers

I'll assume that you're not using a real Java EE application server like WildFly, TomEE, Payara, 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.

See also:

  • Our JSF wiki page
  • JSF implementations and component libraries
  • Difference between Mojarra and MyFaces
  • In simplest terms, what is a factory?
  • How to properly install and configure JSF libraries via Maven?
like image 156
BalusC Avatar answered Nov 11 '22 17:11

BalusC