且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

我的耳朵无法找到 ejb 模块类

更新时间: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:

  1. lib 模块
  2. ejb-jar1.jar
  3. ejb-jar2.jar
  4. war1.jar
  5. war2.jar

哪里:

  1. lib 模块中的所有 jar 都被认为在同一个模块中;
  2. 每个 WAR 文件中的所有 jar 和类都被认为在同一个模块中;
  3. 每个 ejb-jar 都是一个独立的模块.

通常,每个模块都有自己的类加载器.

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:

  1. 每个 WAR 模块都可以看到它自己的类、每个 EJB jar 中的类以及 EAR/lib 目录中每个 jar 中的类
    • 它看不到其他 WAR 模块中的类;
  1. Each WAR module can see it's own classes, the classes in each EJB jar and the classes in every jar in the the EAR/lib directory
    • it cannot see the classes in other WAR modules;
  • 它看不到任何 WAR 模块中的类;
  • it cannot see the classes in any WAR modules;
  • 他们看不到任何 EJB 模块或 WAR 模块中的类
  • they cannot see classes in any EJB modules or WAR modules

更严格的实现需要定义清单类路径条目,以使 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:

  1. 试图访问 EJB 模块之一或 WAR 模块之一中的类的 lib 模块中的类 - 您是否将 struts2 jar 放在 EAR/lib 目录中?
  2. 试图访问其中一个 WAR 模块中的类的 EJB 模块中的类

说了这么多,你可以让你的生活更轻松,因为你使用的是 JavaEE 7 服务器.只需将包括 EJB 在内的所有内容打包到一个 WAR 文件中.您可能不会从构建和部署 EAR 中获得任何好处