更新时间:2023-09-29 23:24:40
EAR 文件只是各种企业模块(EJB jar、WAR 文件和常规 jar 文件)的容器,其中包含一些明确定义(但经常被误解)的规则哪些班级可以看到哪些.
An EAR file is just a container for various enterprise modules (EJB jars, WAR files and regular jar files) with some well defined (but often misunderstood) rules for which classes can see which.
在大多数情况下,您会看到一个具有以下内部结构的 EAR 文件:
In most cases, you will see an EAR file with the following internal structure:
EAR
-lib
| - utilityA.jar
| - utilityB.jar
| - ...
|- ejb-jarC.jar
|- ejb-jarD.jar
|- ...
|- warE.jar
|- warF.jar
|- ...
出于类可见性的目的,上面的这个 EAR 显示了五个模块:
For the purposes of class visibility, this EAR above shows five modules:
哪里:
通常,每个模块都有自己的类加载器.
Typically, each module has it's own class loader.
现在,JBossAS/WildFly 稍微放宽了类可见性规则,以使开发人员的生活更简单(并且出于历史原因).在这些服务器实现上,规则是:
Now, JBossAS/WildFly relaxes the class visibility rules a little to make developers lives simpler (and for historical reasons). On these server implementations the rules are:
更严格的实现需要定义清单类路径条目,以使 EJB 模块对彼此和 WAR 模块可见.
A stricter implementation would require the definition of manifest Class-path entries in order to make EJB modules visible to each other and WAR modules.
现在,鉴于上述所有问题,您的特定问题很可能是其中之一:
Now, given all of the above your particular problem is most likely one of:
说了这么多,你可以让你的生活更轻松,因为你使用的是 JavaEE 7 服务器.只需将包括 EJB 在内的所有内容打包到一个 WAR 文件中.您可能不会从构建和部署 EAR 中获得任何好处