什么是“Java EE 7 API库”?和“Java EE Web 7 API库”以及何时使用它们? [英] What are "Java EE 7 API Library" and "Java EE Web 7 API Library" and when to use them?

查看:122
本文介绍了什么是“Java EE 7 API库”?和“Java EE Web 7 API库”以及何时使用它们?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个在GlassFish 4.1 / Java EE 7(NetBeans 8.0.2)上运行的未使用Apache Maven的完整Java EE项目。



根据项目功能,CDI依赖项必须被添加到项目/模块,即EE模块和Web模块(和一个类库,如果有的话)。



我有长久以来一直令人困惑的是,人们推荐将Java EE 7 API库或Java EE Web 7 API库添加到编译时类路径中作为CDI依赖项(这些库已捆绑在NetBeans中并且已经可用)

由于这些库包含一组API,可能是从Servlet API开始的整个Java EE堆栈,因此添加这些库中的一个到编译时类路径(特别是在EE项目中)是没有意义的,因为在Java EE应用程序中需要CDI功能。



为什么会显示尤其是在NetBeans中多次当只有 cdi-api.jar 作为CDI依赖项时,添加其中一个库是足够的吗?



在Java EE应用程序中需要CDI功能时,我无法在此站点或其他位置找到规范的答案,以确定要在NetBeans项目中添加哪个库。

解决方案 cdi-api.jar 所有 javaee-api javaee-web-api cdi-api 只是API定义。它们不包含functinality,它们仅包含必要的接口,而不是用于编译代码。结果是,您的应用程序中不应包含任何 javaee-api javaee-web-api ,因为它们已经包含在应用程序服务器中。这个实现也是由应用服务器提供的,它本身很大,有时超过100MB的库。如果你的应用只依赖于CDI,你可以免费使用把 cdi-api 作为依赖关系。如果您想从javaee获得更多,则最好选择其中一个配置文件(全部或网页)。但是,请记住,服务器始终至少提供Web配置文件中包含的所有API,因此也值得考虑使用它。有选择地选择依赖关系只适用于完全不支持Java EE的应用程序服务器(例如Tom EE)。在这种情况下,有时甚至需要在应用程序中包含实现或将其放入服务器中。


I have a full-fledged Java EE project running on GlassFish 4.1 / Java EE 7 (NetBeans 8.0.2) not using Apache Maven.

Depending upon the project functionality, the CDI dependency has to be added to both the projects/modules namely the EE module and the Web module (and a class library, if any).

I have been confusing for a long time seeing people recommending to add either "Java EE 7 API Library" or "Java EE Web 7 API Library" to the compile-time class-path as a CDI dependency (these libraries are bundled in NetBeans and readily available out of the box, when using NetBeans).

Since these libraries contain a collection of APIs possibly the entire Java EE stack starting from the Servlet API, adding one of these libraries to the compile-time class-path (especially in the EE project) does not make sense, when the CDI functionality is needed in Java EE applications.

Why is it suggested many a times especially in NetBeans projects to add one of these libraries, when only cdi-api.jar as a CDI dependency is sufficient?

I do not find a canonical answer on this site nor somewhere else as to which library exactly is to be added in NetBeans projects, when the CDI functionality is required in Java EE applications. Adding only cdi-api.jar goes fine, by the way.

解决方案

All of javaee-api, javaee-web-api and cdi-api are just API definitions. They do not contain the functinality, they contain only necessary interfaces instead to make your code compile. The result is that none of javaee-api nor javaee-web-api should be included in your application as they already are included with the application server. The implementation is also provided by the application server, which itself is quite big, sometimes with over 100MB of libraries.

If your application just depends on CDI, you are free to put just cdi-api as a dependency. If you want more from javaee, then it is better to choose one of the profiles (full or web). However, mind that the server always provides at least all API included in web profile, therefore it is worth to consider using it too. Picking dependencies selectively is worth only with application servers, which do not support Java EE completely (e.g. Tom EE). In that case, you sometimes even need to include the implementation with your application or put it inside the server.

这篇关于什么是“Java EE 7 API库”?和“Java EE Web 7 API库”以及何时使用它们?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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