Ejb3 Glassfish development in Eclipse

I’m trying to develop a vaadin application in Eclipse with glassfish and Ejb3.
I read various articles about Vaadin - Ejb3 integration, but no clear path in the development with Eclipse.

I want to follow these steps:

  1. create EAR project

  2. create EJB project

  3. create Vaadin project

  4. obvious

  5. I created a session bean with a method that return a simple string.

I added the ear in glassfish server and so far everything is ok.

  1. I do “new Vaadin project” with all defaults

I try “run to server” and it’s ok.

And now the hard thing.

a. In Java build path I added in Projects the Ejb project.

b. Following one of the examples I wrote this class (after adding a constructor in the Application class (Test30vaadinApplication) ):

[i]
@WebServlet(urlPatterns = “/*”)
public class Servlet extends AbstractApplicationServlet {

@EJB
Test30Ejb personManager;

@Override
protected Application getNewApplication(HttpServletRequest request) throws ServletException {
    return new Test30vaadinApplication(personManager);
}

@Override
protected Class<? extends Application> getApplicationClass() throws ClassNotFoundException {
    return Test30vaadinApplication.class;
}

}
[/i]

c. In the init method of the Application class I used the bean by getting the string of the bean method.

d. I tried various things and always Glassfish gives me an error:
d1. add vaadin project in Java EE dependencies of EAR project
d2. run on server
d3. delete the web.xml file
d4. edit the web.xml file to substituite the default servlet with the custom servlet.

I don’t know what else to try.
What am I doing wrong?
Can someone give me a clean path to develop in Eclipse an application that uses Ejb3 with Glassfish?
Thank you in advance.

Hi,

I don’t use Eclipse, but maybe I can still save you a little trouble. There should be plenty of other tutorials about how to create web applications with Eclipse. Just follow one of those, and then add the EJBs and Vaadin servlet.

Since you want to use EJB3, then I assume you’re using a Java EE 6 container. In that case, you don’t need a separate EJB and EAR project. Just add the EJBs to your web app. I have an example here, but there’s nothing specific to any IDE to create this:

http://blogs.sun.com/bobby/entry/a_simple_ui_for_exploring

That blog is old enough that the pom.xml info is probably out of date, but the Java code should be simple enough to follow.

Cheers,
Bobby

Oops, I’m thinking of EJB 3.1. Some days I can’t keep
everything
straight.

So I think you’re on the right path, but probably you should add the Vaadin dependency to the war file inside the ear, not to the ear itself. Just drop it in WEB-INF/lib and that’s all you need (your EJB layer should not depend on Vaadin). You also don’t need the @WebServlet annotation if you’re including a mapping of your servlet in the web.xml file. Let me know if that works for you, and let me know what errors you see.

I have a complete working app that uses Vaadin with EJB 3.0 and runs on GlassFish 2.X. I can include a pointer to it if that would help you. It uses a bunch of resources and does more than you need, but it would give you an example of what should be in the descriptor files and all that.

Cheers,
Bobby