以及何时使用它们

以及何时使用它们

本文介绍了什么是“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依赖项时,添加其中一个库是足够的吗?



解决方案

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库”以及何时使用它们?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-28 16:21