我是否需要jsf-api或jsf-impl或两者来开始使用JSF?他们为什么不合并? [英] Do I need jsf-api or jsf-impl or both to start using JSF? Why are they not merged?

查看:85
本文介绍了我是否需要jsf-api或jsf-impl或两者来开始使用JSF?他们为什么不合并?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经开始研究JSF了,我想知道在我们的类路径中包含哪些JAR以开始使用JSF。是 jsf-api 还是 jsf-impl ?或者我们必须包括两者?如果它们都是为什么它们没有被合并?

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?

推荐答案

我会假设你没有使用真正的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?

这篇关于我是否需要jsf-api或jsf-impl或两者来开始使用JSF?他们为什么不合并?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆