且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

我是否需要jsf-api或jsf-impl或两者来开始使用JSF?他们为什么不合并?

更新时间:2023-12-04 17:23:22

我会假设你没有使用真正的Java EE应用服务器,如 WildFly TomEE GlassFish 等,但是像 Tomcat 确实没有随附JSF,你必须手动安装它。否则,所有这些与JAR的大惊小怪都是不必要的。

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.


是jsf- api或jsf-impl?或者我们必须包括两者?

你需要两者。 jsf-api.jar 包含API,它几乎只存在抽象类和接口。它是您在代码中导入和使用的 javax.faces。* 类型。 jsf-impl.jar 包含实现,它存在真正的工作代码。该实现是通过API中的工厂在内部加载的。这是 com.sun.faces。* 类,您应该直接在您的代码中导入和使用。如果你这样做,那么你将无法切换到不同的JSF实现,例如MyFaces。

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.


如果两者都没有合并?

存在合并的JAR, javax.faces.jar 。您可以选择这一个而不是两个松散的JAR。只需导航到下载部分javaserverfaces.java.net/rel =nofollow noreferrer> Mojarra主页找到 Maven存储库,带有 javax.faces.jar 文件。目前最新的Mojarra版本是 2.2.11 ,所以选择 javax.faces-2.2.11.jar

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.

  • Our JSF wiki page
  • JSF implementations and component libraries
  • Difference between Mojarra and MyFaces
  • In simplest terms, what is a factory?