eclipse 如何在服务器上部署 EJB?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2535837/
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 14:34:31  来源:igfitidea点击:

How to deploy EJB on server?

eclipsedeploymentjbossglassfishejb-3.0

提问by Shekhar

I am learning EJB3 from last few days. I have many questions regarding EJB, application servers and deployment of EJB.

我最近几天正在学习 EJB3。我有很多关于 EJB、应用服务器和 EJB 部署的问题。

To start with, I have created one simple helloworld stateless session bean but I don't know how to deploy it on server. It has single bean class, bean interface and one servlet client. I have used eclipse to develop this project.
None of the books that I read gives step by step details about how to put EJB on server and how to access those beans.

首先,我创建了一个简单的 helloworld 无状态会话 bean,但我不知道如何在服务器上部署它。它具有单个 bean 类、bean 接口和一个 servlet 客户端。我已经使用 eclipse 来开发这个项目。
我读过的书都没有详细介绍如何将 EJB 放在服务器上以及如何访问这些 bean。

I have JBoss 6 server and I also have Java EE budle downloaded from sun website. Does this Java EE bundle contains Glassfish server? or do I need to download it separately?
Can anyone please give me step by step details of how to put my bean and its client on server (JBoss or Java EE)?

我有 JBoss 6 服务器,我也有从 sun 网站下载的 Java EE budle。这个 Java EE 包是否包含 Glassfish 服务器?还是需要单独下载?
谁能给我一步一步地详细说明如何将我的 bean 及其客户端放在服务器(JBoss 或 Java EE)上?

And why do we need to include bean interface class in EJB client code? I mean either we need to keep client and bean in same package or if we keep them in seperate packages we need to import bean interfaces in client code. Am I right?

为什么我们需要在 EJB 客户端代码中包含 bean 接口类?我的意思是要么我们需要将客户端和 bean 保存在同一个包中,或者如果我们将它们保存在单独的包中,我们需要在客户端代码中导入 bean 接口。我对吗?

采纳答案by Pascal Thivent

With Java EE 6, you can package your Servlet and your EJB in a WAR(either package your EJB in a JAR and put it in WEB-INF/libor simply put allclasses in WEB-INF/classes). And to deploy this WAR, copy it to:

使用Java EE 6,您可以将 Servlet 和 EJB打包到WAR 中(或者将 EJB 打包到 JAR 中并将其放入,WEB-INF/lib或者只是将所有类放入中WEB-INF/classes)。要部署此 WAR,请将其复制到:

  • $GLASSFISH_HOME/domains/<domain1>/autodeployfor GlassFish v3*
  • $JBOSS_HOME/server/default/deployfor JBoss 6
  • $GLASSFISH_HOME/domains/<domain1>/autodeploy适用于 GlassFish v3 *
  • $JBOSS_HOME/server/default/deploy对于 JBoss 6

With Java EE 5, you'll have to package your code in a EAR.

使用Java EE 5,您必须将代码打包到 EAR 中。

And if you want to deploy your application from Eclipse (using the Eclipse WTP), you'll have to install the appropriate server adapter. For Eclipse Galileo and GlassFish (there is currently no adapter for JBoss 6 AFAIK), right-clickthe server view, select New > Server, click on Download additional server adaptersand select the GlassFishadapter. Finish to define your new GlassFish v3 Java EE 6 server and deploy your application on it (right-clickon your application then Run As > Run on Server). For Eclipse Helios and GlassFish, you can follow the link given by @VonC (manual install) or check this answer(install via the Update Site).

如果您想从 Eclipse 部署您的应用程序(使用 Eclipse WTP),您必须安装适当的服务器适配器。对于 Eclipse Galileo 和 GlassFish(目前没有适用于 JBoss 6 AFAIK 的适配器),右键单击服务器视图,选择New > Server,单击下载其他服务器适配器并选择GlassFish适配器。完成以定义新的 GlassFish v3 Java EE 6 服务器并在其上部署您的应用程序(右键单击您的应用程序,然后单击Run As > Run on Server)。对于 Eclipse Helios 和 GlassFish,您可以按照@VonC 提供的链接(手动安装)或查看此答案(通过更新站点安装)。

回答by Thiago

You should export as EJB into your jboss<version>\server/default/deployfolder and then add the build path for it on the servlet's web project. You can "Run on Server" and choose an application server just like you would in any project, no need to export the WAR although if you do that, you're gonna have to re-export your WAR every time you modify your code
AFAIK there's no Eclipse plugin for JBoss 6 but Eclipse provides one for 5.1

您应该将 EJB 作为 EJB 导出到您的jboss<version>\server/default/deploy文件夹中,然后在 servlet 的 Web 项目中为其添加构建路径。您可以像在任何项目中一样“在服务器上运行”并选择一个应用程序服务器,无需导出 WAR,但如果这样做,每次修改代码时都必须重新导出 WAR
AFAIK JBoss 6 没有 Eclipse 插件,但 Eclipse 为 5.1 提供了一个

回答by VonC

You need to add GlassFish to your Eclipse installation (see GlassFish plugin for Eclipse).

您需要将 GlassFish 添加到 Eclipse 安装中(请参阅Eclipse 的 GlassFish 插件)。

The full process is described here(with the latest Eclipse Helios 3.6M6)

此处描述了完整过程(使用最新的 Eclipse Helios 3.6M6)