eclipse EJB 关于 EAR 与 WAR 的解释

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3923514/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 15:11:21  来源:igfitidea点击:

EJB explanation regarding EAR vs WAR

javaeclipseejbwarear

提问by Anand Sunderraman

I have just begun reading up on EJBs.

我刚刚开始阅读 EJB。

Even as I venture into it I have a few questions based on what I have heard about them.

即使我冒险进入它,我也有一些基于我所听到的关于它们的问题。

  1. Do applications using EJBs always have to be deployed as an EAR?
  2. Can applications containing EJBs be deployed just like other other java web projects using ECLIPSE and without using ANT?
  1. 使用 EJB 的应用程序是否总是必须部署为 EAR?
  2. 包含 EJB 的应用程序是否可以像其他使用 ECLIPSE 且不使用 ANT 的其他 Java Web 项目一样部署?

回答by JoseK

1.Do applications using ejb's always have to be deployed as EAR ?

1.使用 ejb 的应用程序总是必须部署为 EAR 吗?

No.

不。

The EJB module is assembled into a JAR, lets call it myapp-ejb.jar as a naming convention.

EJB 模块被组装成一个 JAR,作为命名约定,我们称之为 myapp-ejb.jar。

This contains the EJB code as well as the deployment descriptor file called ejb-jar.xml in EJB 2.x. In EJB 3.0, the code itself contains the annotations required for the server to understand for deployment, so the deployment descriptors are optional. The deployment descriptor/annotations cover basic stuff needed for EJB deployment like the JNDI, DataSource look up etc.

这包含 EJB 代码以及 EJB 2.x 中名为 ejb-jar.xml 的部署描述符文件。在 EJB 3.0 中,代码本身包含服务器理解部署所需的注释,因此部署描述符是可选的。部署描述符/注释涵盖了 EJB 部署所需的基本内容,如 JNDI、数据源查找等。

A collection of multiple EJB modules and other Web modules (war) together make up an EAR. As @Isaac pointed out, an EAR doesn't have to include any WAR file in it. The only condition for an EAR file is to contain at least one J2EE module of any kind.

多个 EJB 模块和其他 Web 模块 (war) 的集合共同构成了一个EAR。正如@Isaac 指出的那样,EAR 不必在其中包含任何 WAR 文件。EAR 文件的唯一条件是至少包含一个任何类型的 J2EE 模块。

The EAR needs a META-INF/application.xmlwhich lists all the EJB jars and wars present in the EAR. So you go for an EAR when you have multiple EJB modules which is usually the case, hence the usual deployment is of an EAR.

EAR 需要META-INF/application.xml列出 EAR 中存在的所有 EJB jars 和 wars。因此,当您有多个 EJB 模块时,通常会选择 EAR,因此通常的部署是 EAR。

An example of this file is shown below taken from http://download.oracle.com/docs/cd/B32110_01/web.1013/b28221/undejdev003.htm. This is a good article for you to read.

该文件的示例如下所示,取自http://download.oracle.com/docs/cd/B32110_01/web.1013/b28221/undejdev003.htm。这是一篇很好的文章,供您阅读。

<application>
  <display-name>master-application</display-name>
  <module>
    <ejb>ejb1.jar</ejb>
  </module>
  <module>
    <ejb>ejb2.jar</ejb>
  </module>
  <module>
    <java>appclient.jar</java>
  </module>
  <module>
    <web>
        <web-uri>clientweb.war</web-uri>
        <context-root>webapp</context-root>
    </web>
  </module>
  <module>
    <ejb>ejb3.jar</ejb>
  </module>

2.Can applications containing EJB's be deployed just like other other java web projects using ECLIPSE and without using ANT

2.可以像其他java web项目一样使用ECLIPSE而不使用ANT来部署包含EJB的应用程序吗

Yes, once an EAR/JAR is assembled it can be deployed into a server (via Eclipse if you wish).

是的,一旦 EAR/JAR 组装好,就可以将其部署到服务器中(如果您愿意,可以通过 Eclipse)。

Ant is a build tool which has nothing to do with the actual deploying of the EJB code. It is used to compile and assemble the JAR - which can be done from Eclipse as well.

Ant 是一个构建工具,它与 EJB 代码的实际部署无关。它用于编译和组装 JAR - 这也可以从 Eclipse 完成。

Here is a tutorial which does just that.

是一个教程,它就是这样做的

Further Reading

进一步阅读

Packaging Applications

包装应用

Packaging EJB3 Applications

打包 EJB3 应用程序