Problem getting Vaadin Flow to work from embedded jetty and Gradle

I am trying to get a small test project to work using embedded jetty, gradle, and Vaadin 14. This is part of our effort to port our vaadin 8 application which already uses embedded jetty.

I took the embeded-jetty-demo from https://github.com/alejandro-du/embedded-jetty-demo.git
and changed it to use gradle instead of maven. See attachment.

When I build and run using embedded jetty and open localhost:8080 I see a directory of files provided by jetty instead of the vaadin app which should show “Does it work?”

  • gradle vaadinPrepareFrontend
  • gradle fatJar
  • java -jar ./build/libs/all-in-one-jar.jar
  • Open http://localhost:8080 in browser and you see a directory of files. What you should see is
    a button which says “Does it work?”

It works if I launch via gjetty gradle plugin which bypasses the embedded jetty code:

  • gradle appRun

As a side note running “gradle vaadinBuildFrontend” never finishes. I have to kill it off after 10-15 minutes. That is perhaps a gradle vaadin plugin bug.

SETUP:

  • OpenJDK 8
  • Gradle 6.3
  • Gradle plugin com.vaadin 0.6.0
  • Jetty 9.4

Updated test project attached here.

18241486.zip (71.4 KB)

Hi Mike, maybe this example project will be of use https://github.com/mvysny/vaadin14-embedded-jetty-gradle

Erik Lumme:
Hi Mike, maybe this example project will be of use https://github.com/mvysny/vaadin14-embedded-jetty-gradle

Thanks Erik! I did not see that example. It sounds perfect except it doesn’t work.

When I clone and run it I get this in the browser window:

Could not navigate to ''
Reason: Couldn't find route for ''
Available routes:
This detailed message is only shown when running in development mode.

So close. So frustrating.

Strangely if I run “gradle run” from CLI it works fine. So something is wrong when I launch from eclipse.

I was able to get this to work from Eclipse by adding “build\classes\java\main” to the eclipse launcher classpath.

Hi, thank you for posting and I’m happy that you were able to resolve the issue.

The Could not navigate to '' message and the Available routes: message tells you that no @Route-annotated classes have been found on your classpath. You correctly worked around this issue by adding build\classes\java\main to the classpath.

However, the build\classes\java\main path is a standard path for classes output: I wonder whether the issue is actually somewhere in the Eclipse+Buildship direction? I have found a similar issue and a discussion here: https://discuss.gradle.org/t/how-to-add-srcdir-only-for-eclipse-buildship/27007

Martin Vyšný:
Hi, thank you for posting and I’m happy that you were able to resolve the issue.

The Could not navigate to '' message and the Available routes: message tells you that no @Route-annotated classes have been found on your classpath. You correctly worked around this issue by adding build\classes\java\main to the classpath.

However, the build\classes\java\main path is a standard path for classes output: I wonder whether the issue is actually somewhere in the Eclipse+Buildship direction? I have found a similar issue and a discussion here: https://discuss.gradle.org/t/how-to-add-srcdir-only-for-eclipse-buildship/27007

That buildship issue does seem like the same thing I encountered.

Dear forum,

I have exactly the same problem with Visual Code Studio which is based on BuildShip too.
Could you tell me where I have to add the build\classes\java\main path ?
There’s a configuration to set in the gradle.build file ?

Regards,
Stefano

Dear Forum,

I found a solution to this problem and I am now able to use Visual Studio Code with Vaadin, Gradle and a Jetty embedded.
The short answer is that you have to add this configuration in the gradle build file:

eclipse {
    classpath {
        file {
            whenMerged {
                def src = entries.find { it.path == 'src/main/java' }
                src.output = "/$eclipse.project.name/classes/main-java"
            }
        }
    }
}

You could find more information and a complete skeleton project here: [Visual Code Studio @Route error]
(https://github.com/mvysny/vaadin14-embedded-jetty-gradle/issues/4)
For the complete explanation the info are here: [Gradle and Buidship not working for Vaadin project]
(https://discuss.gradle.org/t/gradle-and-buidship-not-working-for-vaadin-project/37463) and here: [Improved Java project synchronization]
(https://discuss.gradle.org/t/buildship-1-0-18-is-now-available/19012)

Regards,
S.