简体   繁体   English

如何将 EJB 功能添加到 Eclipse 动态 web 项目?

[英]How do I add EJB capabilities to an Eclipse dynamic web project?

I am developing a simple application with EJB 3.0 using OpenEJB for deployment and Eclipse as an IDE.我正在使用 EJB 3.0 开发一个简单的应用程序,使用 OpenEJB 进行部署,并将 Eclipse 作为 IDE。

I created the project as a 'dynamic web application' in Eclipse. When I tried creating the first stateless session bean, I realized that the @Remote annotation could not be resolved.我在 Eclipse 中将项目创建为“动态 web 应用程序”。当我尝试创建第一个无状态 session bean 时,我意识到无法解析 @Remote 注释。

What is the right way to fix this problem?解决此问题的正确方法是什么?

  1. Delete the project and create a new 'enterprise application project' (this seems to be pretty heavy weight, so I am not sure I want to go in this direction)?删除项目并创建一个新的'企业应用程序项目'(这似乎很重,所以我不确定我要go这个方向)?
  2. Delete the project and create an EJB project (this does not seem to be right because I believe such a project will only let me bundle the EJB part of the application)?删除项目并创建一个 EJB 项目(这似乎不对,因为我相信这样的项目只会让我捆绑应用程序的 EJB 部分)?
  3. Add some libraries to my existing project (is there a library pack for EJB 3.x)?将一些库添加到我现有的项目中(是否有用于 EJB 3.x 的库包)?
  4. Add a facet to my existing project (I tried to see if I can add a facet, but I cannot see an EJB facet within the context of this project)?向我现有的项目添加一个方面(我试图查看是否可以添加一个方面,但我在该项目的上下文中看不到 EJB 方面)?

Thanks for helping.感谢您的帮助。

Update: I found the answer.更新:我找到了答案。

TomEE's installation has a directory containing all the jar files needed to compile and run EJB's 'apache-tomee-webprofile-1.0.0-beta-2/webapps/openejb/lib' TomEE 的安装目录包含编译和运行 EJB 的“apache-tomee-webprofile-1.0.0-beta-2/webapps/openejb/lib”所需的所有 jar 文件

I created a User Library in Eclipse containing all the jars from the lib folder described above and added it to the build path.我在 Eclipse 中创建了一个用户库,其中包含上述 lib 文件夹中的所有 jars,并将其添加到构建路径中。

The EJB interfaces now compile properly. EJB 接口现在可以正确编译。

  1. Create an new Enterprise Application Project (EAP)创建新的企业应用程序项目 (EAP)
  2. Create an new EJB Project and add it to the EAP创建一个新的 EJB 项目并将其添加到 EAP
  3. Add to the EAP your existent WEB project将您现有的 WEB 项目添加到 EAP

Now you can create EJBs in the EJB project and call them from the WEB project.现在您可以在 EJB 项目中创建 EJB 并从 WEB 项目中调用它们。

And you can deploy or debug your EAP on an Application Server (like JBoss) that supports Enterprise Application Projects.您可以在支持企业应用程序项目的应用程序服务器(如 JBoss)上部署或调试您的 EAP。 The EAP is deployed as a unique file with .ear extension. EAP 被部署为带有.ear扩展名的唯一文件。

If you use Tomcat for example you cannot deploy the ear packages.例如,如果您使用 Tomcat,则无法部署ear包。

Here a page with a description about creating ear with Eclipse.这是一个页面,其中包含有关使用 Eclipse 创建耳朵描述

A simple way to add eclipse library support for TomEE or TomEE+ is the following:为 TomEE 或 TomEE+ 添加 eclipse 库支持的简单方法如下:

  1. Create a Tomcat 7 server in eclipse. (Change the name to reflect it's TomEE)在 eclipse 中创建一个 Tomcat 7 服务器。(更改名称以反映它是 TomEE)
  2. Point it to your tomEE install directory.将它指向您的 tomEE 安装目录。
  3. In your project goto: Properties -> Java Build Path -> Libraries.在您的项目中转到:Properties -> Java Build Path -> Libraries。
  4. Press "Add library".按“添加库”。
  5. Select "Server runtime", and press next. Select“服务器运行时”,然后按下一步。
  6. Select the TomEE server profile you just created and click finish. Select 您刚刚创建的 TomEE 服务器配置文件,然后单击完成。
  7. Click OK.单击确定。

The tomEE libraries have been added to your eclipse project. tomEE 库已添加到您的 eclipse 项目中。

I'm using maven and get it work with the following simple steps:我正在使用 maven 并通过以下简单步骤让它工作:

  1. Open Project -> Properties -> Deployment Assembly打开项目 -> 属性 -> 部署程序集
  2. Click 'Add...'单击“添加...”
  3. Choose 'Java Build Path Entries'选择“Java 构建路径条目”
  4. Choose 'Maven Dependencies'选择“Maven 依赖项”

That's it!而已!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM