How do I add EJB capabilities to an Eclipse dynamic web project?
Asked Answered
R

3

11

I am developing a simple application with EJB 3.0 using OpenEJB for deployment and Eclipse as an 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.

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) ?
  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) ?
  3. Add some libraries to my existing project (is there a library pack for 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) ?

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'

I created a User Library in Eclipse containing all the jars from the lib folder described above and added it to the build path.

The EJB interfaces now compile properly.

Rainier answered 10/4, 2012 at 9:50 Comment(1)
The solution you have found would be the same as @Greg below, but slightly less elegant.Leasehold
S
16
  1. Create an new Enterprise Application Project (EAP)
  2. Create an new EJB Project and add it to the EAP
  3. Add to the EAP your existent WEB project

Now you can create EJBs in the EJB project and call them from the WEB project.

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.

If you use Tomcat for example you cannot deploy the ear packages.

Here a page with a description about creating ear with Eclipse.

Shilohshim answered 13/4, 2012 at 7:46 Comment(0)
I
8

A simple way to add eclipse library support for TomEE or TomEE+ is the following:

  1. Create a Tomcat 7 server in eclipse. (Change the name to reflect it's TomEE)
  2. Point it to your tomEE install directory.
  3. In your project goto: Properties -> Java Build Path -> Libraries.
  4. Press "Add library".
  5. Select "Server runtime", and press next.
  6. Select the TomEE server profile you just created and click finish.
  7. Click OK.

The tomEE libraries have been added to your eclipse project.

Ineligible answered 14/5, 2012 at 9:1 Comment(0)
S
-3

I'm using maven and get it work with the following simple steps:

  1. Open Project -> Properties -> Deployment Assembly
  2. Click 'Add...'
  3. Choose 'Java Build Path Entries'
  4. Choose 'Maven Dependencies'

That's it!

Sibyl answered 28/11, 2012 at 20:41 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.