use vaadin application with embedded jetty


I’m completely new to Vaadin so forgive me if I’m asking the obvious :wink:

I am developing an application that has an embedded jetty server.
The application also needs a web interface to interact with it.
For this I was thinking to use Vaadin, but I have no clue how I can/should add my Vaadin application to the embedded jetty server.

So let’s say that I have a Vaadin application called “VaadinTestGUI” which should be integrated with my application (let’s say “MyTestApp”) through jetty.
My own servlets are defined like this:

WebAppContext testAppContext = new WebAppContext();
testAppContext.addServlet(new ServletHolder(new MyOwnTestServlet(parent)), “/testservlet/*”);

=> Can I just add my Vaadin application in a similar way ?
Something like this:

ServletHolder vaadinLoader = new ServletHolder(new com.vaadin.terminal.gwt.server.ApplicationServlet());
testAppContext.addServlet(vaadinLoader, “/vaadin/*”);

Would this work ?

I need to be able to pass one or more objects from my own application to the Vaadin application,
that’s why I’m using a ServletHolder in the example above (but I’m not sure this is the way to go)

Can someone give me some advise with this please ?



In the meantime I got it partially working.

What is working:
After manually copying some extra files, extracting some jars, etc, I can access the Vaadin GUI through the jetty server which is embedded in my application.

What is not working:

  • as mentioned above, I need to manually copy and/or extract some extra files (parts of the themes, widgetsets, …)
  • I can’t access my application code from within the Vaadin GUI application, as I have no clue how to pass existing java objects to the Vaadin application.
    (I hope this is possible, otherwise I’m afraid Vaadin isn’t the right solution for me :frowning: )

As mentioned in my post above, I pass objects to my own servlets in this way:
testAppContext.addServlet(new ServletHolder(new MyOwnTestServlet(parent)), “/testservlet/*”);
(where “parent” is the java object I need to pass to the servlet)

Any suggestions welcome…

For finding the resources, you might need to call setResourceBase() and possibly set the classloader to use as well.

For an example of a working embedded Jetty configuration,
see here

Does your servlet inherit ApplicationServlet or AbstractApplicationServlet?

What is the problem you see here - an exception? At what time?

While I have not used such a configuration, I imaging one possible problem could be the classloader used.

Thanks, I’ll take a look at that

My own servlets just extend HttpServlet, so nothing fancy there.
For the Vaadin application I don’t get any exceptions or such, it’s just that I have no clue how I can pass my existing objects from my own application to the Vaadin application.
The most important difference between my own servlets and the Vaadin application in regards to passing objects is that my own servlets are called directly through the ServletHolder, e.g.:

testAppContext.addServlet(new ServletHolder(new MyOwnTestServlet(parent)), "/testservlet/*");

while the Vaadin application is loaded through “com.vaadin.terminal.gwt.server.ApplicationServlet”:

ServletHolder vaadinLoader = new ServletHolder(new com.vaadin.terminal.gwt.server.ApplicationServlet());
testAppContext.addServlet(vaadinLoader, "/vaadin/*");

As far as I know I can only try to pass my parent object (in this example) to the gwt ApplicationServlet:


but then how can I access that parent object from the Vaadin application itself (i.e. VaadinTestGui) ?

ok, I’ve got it working but I’m not sure this is the recommended way to do it or maybe it’s even discouraged ?

This is what I did:

  1. I wrote my own TestApplication class which extends the Vaadin Application class and has a constructor
    that accepts the objects that I need to pass from my server application to my Vaadin application

  2. I wrote my own TestApplicationServlet class which extends the Vaadin ApplicationServlet class and also has a constructor that accepts the objects that I need to pass from my server application.
    And it also creates a new TestApplication instance instead of the regular Application instance and additionally passes the object(s) received through the servlets constructor

  3. Now I can map the new servlet onto my jetty context as usual:

ServletHolder vaadinLoader = new ServletHolder(new TestApplicationServlet(parent));
testAppContext.addServlet(vaadinLoader, "/vaadin/*");

This works, but as I said I’m not sure if this is a recommended approach as I am overriding some core Vaadin classes.
Any feedback appreciated

While inheriting a Vaadin core class, you are not getting too deep into the internals.

You could also consider inheriting directly from AbstractApplicationServlet and just overriding the getApplicationClass() and getNewApplication() with trivial implementations (see
this Glassfish example
), removing the need for the application init parameter.

Note that the protected API of AbstractApplicationServlet may change somewhat in the future, but the general approach should remain valid when not working with portlets.

I’m not sure if there would be some easier way to pass such parameters.

I reread this and I think I didn’t express myself clearly enough.
What I meant is that the resources are in the correct location (resourcebase is set correctly) but that
the resources are not complete (e.g. some files from the themes folder are missing)
And I copied all files found in the Webcontent folder of my Vaadin application, which I think is all I need ?

That’s a good point, thanks.

Anybody else ?