Vaadin 10 + Jetty embedded.

Hello. Please help me to fix my mini-project.
It must start embedded Jetty server, connect Vaadin servlet and process HTTP-requests over it.
Project created by Vaadin example and was modified for Jetty embedded support.

When i start project it shows that requests are operates over MyUI (shows in console), but there is no UI in browser page.
In browser debug panel i was found that string:

“\n\tCould not navigate to ‘’\n\t\x3Cp>Reason: Couldn’t find route for ‘’\x3C/p>\n\t\x3Cp>\x3C/p>\x3Cdiv>Available routes:\x3C/div>\n\t\x3Cp>\x3C/p>\n\t\x3Cul>\n\t\t\n\t\x3C/ul>\n\t\x3Cp>This detailed message is only shown when running in development mode.\x3C/p>\n”

Attachment
17266537.zip (75.7 KB)

May someone can give me a link to github project with Jetty embedded and Vaadin servlet attached?

Your Jetty fails to provide some resources. Pretty sure those are needed for the site to function (see image).

Iirc you also need to set a few parameters for Jetty’s webcontext.
For instance context.setAttribute(“org.eclipse.jetty.server.webapp.ContainerIncludeJarPattern”, “./" + webappDirectory + "/.”); (taken from https://github.com/alejandro-du/jetty-vaadin/blob/master/src/main/java/org/vaadin/jetty/VaadinJettyServer.java)

Also for V10 I think you need to set context.setBaseResource( ); to a resource collection that includes all relevant resources.

I try to change the code, but it always the same. Can’t get it work.

Ronny Edler:
Your Jetty fails to provide some resources. Pretty sure those are needed for the site to function (see image).

Iirc you also need to set a few parameters for Jetty’s webcontext.
For instance context.setAttribute(“org.eclipse.jetty.server.webapp.ContainerIncludeJarPattern”, “./" + webappDirectory + "/.”); (taken from https://github.com/alejandro-du/jetty-vaadin/blob/master/src/main/java/org/vaadin/jetty/VaadinJettyServer.java)

Also for V10 I think you need to set context.setBaseResource( ); to a resource collection that includes all relevant resources.

I edited Context creator, add attribute “org.eclipse.jetty.server.webapp.ContainerIncludeJarPattern”, but there is the same error.

    /**
     * ServletContextHandler initializer
     */
    private ServletContextHandler createServletContextHandlerApplication() {
        ServletContextHandler servletContextHandler = new ServletContextHandler(ServletContextHandler.SESSIONS);
        servletContextHandler.setContextPath(webContextApplication);

        servletContextHandler.setAttribute("org.eclipse.jetty.server.webapp.ContainerIncludeJarPattern", ".*/" + "target/classes" + "/.*");

        servletContextHandler.setInitParameter("ui", MyUI.class.getCanonicalName());
        servletContextHandler.addServlet(MyServlet.class, "/*");

        return servletContextHandler;
    }

If i start Maven “package” then there is no new files generated in /target/classes folder and no /VAADIN folder created. Is it normal?
How to get files that must be generated on Maven “package”?

Hi Alexander, have you managed to get 10x/11x Vaadin embedded?

Eugene Kondrashev:
Hi Alexander, have you managed to get 10x/11x Vaadin embedded?

No, we haven’t yet.

I think I have a similar question/problem trying to rewrite a Vaadin 8 application for Vaadin 11. The Vaadin 8 version programatically launches an embedded Jetty server and it would be helpful to see a Jetty example that works for 11.

Is there any update regarding this issue. I am too facing this problem.

I am also desperate looking for a working example of how to get Vaadin 12 to work with embedded Jetty. It used to work with Vaadin 7 and 8, but I can not get it right with Vaadin 12.

Forget the ServletContext configuration and see my post: https://vaadin.com/forum/thread/17483200/vaadin-12-with-jetty-embedded-within-an-osgi-bundle-missing-vaadin-sta

Most important part is the custom RouteRegistry. In addition you need to add the following static resource lookup (HTTP → classpath):

/frontend/ → /META-INF/resources/frontend/

/frontend/bower_components/ → /META-INF/resources/webjars/

/VAADIN/ → /META-INF/resources/VAADIN/

…maybe more, I just got it basically working!

I am using a JAX-RS component for the resources. That’s why I don’t have the full example just now.

“asyncSupported = true” needs to be set in the ServletContext configuration!

Hi Martin,

Once you get yours working, would you be so kind to post the full example including the relative locations of the resources/jars that are needed?

I think the Vaadin docs (book of Vaadin, etc) should have a section explaining how to get Vaadin Flow working with embedded Jetty. It seems like it is an important topic for enough people.

Thank you so much for your help.

Are you guys using this embedded Jetty in production environments or only in development/testing?

i am using it in both test and production as a lightweight web server

I just uploaded an example that creates an executable uber-jar using Vaadin 12+: https://github.com/alejandro-du/embedded-jetty-demo

Basically, you have to configure the server as follows:

public class Application {

    public static void main(String... args) throws Exception {
        new Application().run(8080, "/");
    }

    public void run(int port, String contextPath) throws Exception {
        URL webRootLocation = this.getClass().getResource("/META-INF/resources/");
        URI webRootUri = webRootLocation.toURI();

        WebAppContext context = new WebAppContext();
        context.setBaseResource(Resource.newResource(webRootUri));
        context.setContextPath(contextPath);
        context.setAttribute("org.eclipse.jetty.server.webapp.ContainerIncludeJarPattern", ".*");
        context.setConfigurationDiscovered(true);
        context.setConfigurations(new Configuration[]{
                new AnnotationConfiguration(),
                new WebInfConfiguration(),
                new WebXmlConfiguration(),
                new MetaInfConfiguration(),
                new FragmentConfiguration(),
                new EnvConfiguration(),
                new PlusConfiguration(),
                new JettyWebXmlConfiguration()
        });
        context.getServletContext().setExtendedListenerTypes(true);
        context.addEventListener(new ServletContextListeners());

        Server server = new Server(port);
        server.setHandler(context);

        server.start();
        server.join();
    }

}

Also, you need to use the maven-shade-plugin to package the artifact in an uber-jar.

How can it be done without WebAppContext?

Here is an up to date step by step tutorial on how to get embedded Jetty into your Vaadin Flow app: https://vaadin.com/tutorials/embedded-jetty-server-in-vaadin-flow

@Martin: maybe ServletContextHandler? What is the limitation with WebAppContext?