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

查看:13
本文介绍了我是否需要 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 应用服务器,例如 WildFlyTomEEPayara 等,但像 Tomcat 开箱即用的 JSF 确实不附带,因此您必须手动安装它.否则,所有这些对 JAR 的大惊小怪都是不必要的.

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.

是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.

There exist a merged JAR, the javax.faces.jar. You can pick this one instead of the two loose JARs.

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

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