如何将 EJB 功能添加到 Eclipse 动态 Web 项目?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10086492/
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
How do I add EJB capabilities to an Eclipse dynamic web project?
提问by Ragini
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 应用程序”。当我尝试创建第一个无状态会话 bean 时,我意识到无法解析 @Remote 注释。
What is the right way to fix this problem ?
解决这个问题的正确方法是什么?
- 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) ?
- 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) ?
- Add some libraries to my existing project (is there a library pack for EJB 3.x) ?
- 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项目(这似乎不太对,因为我相信这样的项目只会让我捆绑应用程序的EJB部分)?
- 向我现有的项目添加一些库(是否有用于 EJB 3.x 的库包)?
- 向我现有的项目添加一个方面(我试图查看是否可以添加一个方面,但在此项目的上下文中我看不到 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 文件夹中的所有 jar,并将其添加到构建路径中。
The EJB interfaces now compile properly.
EJB 接口现在可以正确编译。
回答by dash1e
- Create an new Enterprise Application Project (EAP)
- Create an new EJB Project and add it to the EAP
- Add to the EAP your existent WEB project
- 创建新的企业应用程序项目 (EAP)
- 创建一个新的 EJB 项目并将其添加到 EAP
- 将您现有的 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.
The EAP is deployed as a unique file with .ear
extension.
您可以在支持企业应用项目的应用服务器(如 JBoss)上部署或调试您的 EAP。EAP 部署为带有.ear
扩展名的唯一文件。
If you use Tomcat for example you cannot deploy the earpackages.
例如,如果您使用 Tomcat,则无法部署ear包。
Here a page with a descriptionabout creating earwith Eclipse.
这是一个关于使用 Eclipse创建耳朵的描述的页面。
回答by Greg
A simple way to add eclipse library support for TomEE or TomEE+ is the following:
为 TomEE 或 TomEE+ 添加 eclipse 库支持的简单方法如下:
- Create a Tomcat 7 server in eclipse. (Change the name to reflect it's TomEE)
- Point it to your tomEE install directory.
- In your project goto: Properties -> Java Build Path -> Libraries.
- Press "Add library".
- Select "Server runtime", and press next.
- Select the TomEE server profile you just created and click finish.
- Click OK.
- 在 Eclipse 中创建一个 Tomcat 7 服务器。(更改名称以反映它是 TomEE)
- 将其指向您的 tomEE 安装目录。
- 在您的项目中,转到:属性 -> Java 构建路径 -> 库。
- 按“添加库”。
- 选择“服务器运行时”,然后按下一步。
- 选择您刚刚创建的 TomEE 服务器配置文件,然后单击完成。
- 单击确定。
The tomEE libraries have been added to your eclipse project.
tomEE 库已添加到您的 eclipse 项目中。
回答by nosam
I'm using maven and get it work with the following simple steps:
我正在使用 maven 并通过以下简单步骤使其工作:
- Open Project -> Properties -> Deployment Assembly
- Click 'Add...'
- Choose 'Java Build Path Entries'
- Choose 'Maven Dependencies'
- 打开项目 -> 属性 -> 部署程序集
- 点击“添加...”
- 选择“Java 构建路径条目”
- 选择“Maven 依赖项”
That's it!
就是这样!