Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Native #10

Open
mvysny opened this issue Mar 11, 2023 · 9 comments
Open

Native #10

mvysny opened this issue Mar 11, 2023 · 9 comments
Assignees
Labels
blocked by upstream Something needs to be fixed in another library first enhancement New feature or request

Comments

@mvysny
Copy link
Owner

mvysny commented Mar 11, 2023

Native is cool these days. Add support for building with Graalvm; there's a Gradle plugin to build for native. Jetty and class auto discovery needs to be figured out.

@mvysny mvysny added the enhancement New feature or request label Mar 11, 2023
@mvysny mvysny self-assigned this Mar 11, 2023
@mvysny
Copy link
Owner Author

mvysny commented Mar 13, 2023

I've installed GraalVM and went through the tutorial at https://graalvm.github.io/native-build-tools/latest/gradle-plugin-quickstart.html - everything worked well.

Tried the same steps (agent+metadataCopy+nativeCompile) on https://github.com/mvysny/vaadin-boot-example-gradle, but unfortunately I'm getting

java.lang.NullPointerException
        at com.vaadin.flow.server.VaadinServlet.serveStaticOrWebJarRequest(VaadinServlet.java:431)
        at com.vaadin.flow.server.VaadinServlet.service(VaadinServlet.java:386)
        at jakarta.servlet.http.HttpServlet.service(HttpServlet.java:587)
        at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:764)
        at org.eclipse.jetty.servlet.ServletHandler$ChainEnd.doFilter(ServletHandler.java:1665)
        at org.eclipse.jetty.websocket.servlet.WebSocketUpgradeFilter.doFilter(WebSocketUpgradeFilter.java:170)
        at org.eclipse.jetty.servlet.FilterHolder.doFilter(FilterHolder.java:202)
        at org.eclipse.jetty.servlet.ServletHandler$Chain.doFilter(ServletHandler.java:1635)
        at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:527)
        at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:131)
        at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:578)
        at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:122)

which means that VaadinServlet.staticFileHandler is null, which means that VaadinServlet.init() wasn't called. The startup time is instantaneous though - 17ms - which looks really promising.

I've tried to add the [Lorg.eclipse.jetty.servlet.ServletMapping; mapping as per https://javalin.io/2018/09/27/javalin-graalvm-example.html , didn't help. The tutorial looks old so it's probably of no value now. Maybe an updated tutorial of javalin+graalvm could also help.

I'm compiling Vaadin dev mode to native atm which is kind of dumb. I'll try the same thing but with prod mode.

I wonder whether GraalVM is actually compatible with Jetty's classpath scanning. Will study more. Perhaps an up-to-date jetty+graalvm article could help tremendously.

@mvysny
Copy link
Owner Author

mvysny commented Mar 13, 2023

Unfortunately the production build fails with the same exception.

Further things to check out:

@mvysny mvysny added the help wanted Extra attention is needed label Mar 13, 2023
@mvysny
Copy link
Owner Author

mvysny commented Mar 13, 2023

Debugged VaadinServlet in native a bit (by introducing my own MyServlet which extends VaadinServlet, and adding a bunch of stdout statements), found interesting info. VaadinServlet.init() actually does get called, however it soon bails out and does nothing, because Lookup is null. According to https://mvysny.github.io/vaadin-lookup-vs-instantiator/ that means that LookupServletContainerInitializer is not called, which means that Jetty classpath autodiscovery isn't working properly.

@mvysny
Copy link
Owner Author

mvysny commented Mar 13, 2023

Interesting related ticket which suggests that there might be some limitation in Jetty's classpath scanning: mvysny/vaadin-boot-example-maven#1

@mvysny
Copy link
Owner Author

mvysny commented Mar 13, 2023

Could the Quick start be the solution? #11

@mvysny mvysny removed the help wanted Extra attention is needed label Mar 14, 2023
@mvysny
Copy link
Owner Author

mvysny commented Mar 14, 2023

Yup, QuickStart should help. Blocked by #11

@mvysny mvysny added blocked Blocked by another ticket and removed blocked Blocked by another ticket labels Mar 14, 2023
@mvysny
Copy link
Owner Author

mvysny commented Mar 16, 2023

When running the native binary, QuickStart fails with

2023-03-16 13:32:47.747 [main] WARN org.eclipse.jetty.webapp.WebAppContext - Failed startup of context o.e.j.w.WebAppContext@1da6646c{/,resource:/webapp,STOPPED}{resource:/webapp}
java.lang.IllegalStateException: Bad Quickstart location
	at org.eclipse.jetty.quickstart.QuickStartConfiguration.preConfigure(QuickStartConfiguration.java:95)
	at org.eclipse.jetty.webapp.Configurations.preConfigure(Configurations.java:496)
	at org.eclipse.jetty.webapp.WebAppContext.preConfigure(WebAppContext.java:510)

@mvysny
Copy link
Owner Author

mvysny commented Mar 16, 2023

The reason for that is that context.getBaseResource() resolves to resource:/webapp of type URLResource; both URLResource.isDirectory() and URLResource.exists() return false. I've patched QuickStartConfiguration:94 and commented out the check. I've also passed in the path to quickstart-web.xml as ctx.setAttribute(QuickStartConfiguration.QUICKSTART_WEB_XML, new PathResource(new File("src/main/resources/webapp/WEB-INF/quickstart-web.xml")));, and now the native mode works.

I'll polish the native mode, document, file a feature request at Jetty.

@mvysny
Copy link
Owner Author

mvysny commented Mar 17, 2023

Blocked by jetty/jetty.project#9514

mvysny added a commit that referenced this issue Mar 17, 2023
mvysny added a commit that referenced this issue Mar 17, 2023
mvysny added a commit that referenced this issue Mar 17, 2023
@mvysny mvysny added the blocked by upstream Something needs to be fixed in another library first label Mar 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
blocked by upstream Something needs to be fixed in another library first enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant