Skip to content

Commit

Permalink
11 Remove direct support for QuickStart and document it in README.md …
Browse files Browse the repository at this point in the history
…instead. Fixes #11
  • Loading branch information
mvysny committed Mar 17, 2023
1 parent caa184e commit 8bce215
Show file tree
Hide file tree
Showing 2 changed files with 89 additions and 8 deletions.
61 changes: 61 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -695,6 +695,67 @@ Many more example projects:
If you like [Kotlin](https://kotlinlang.org/) and you like the simplicity of the ideas above,
please use the [Vaadin-on-Kotlin](https://www.vaadinonkotlin.eu/) framework which is based on the ideas above.

## Advanced Use-Cases

### Jetty QuickStart

Jetty can optionally start faster if we don't classpath-scan for resources, and instead pass in a QuickStart XML file with all resources listed.
This is mandatory for native mode, since classpath scanning doesn't work in native mode.

See [Jetty QuickStart Documentation](https://www.eclipse.org/jetty/documentation/jetty-12/operations-guide/index.html#og-quickstart)
for more details; see [Jetty Maven plugin](https://www.eclipse.org/jetty/documentation/jetty-12/programming-guide/index.html#jetty-effective-web-xml-goal)
documentation as well on how to generate the QuickStart configuration file.
Also see [Issue #11](https://github.com/mvysny/vaadin-boot/issues/11).

To enable QuickStart mode, add a dependency on Jetty QuickStart: `org.eclipse.jetty:jetty-quickstart:11.0.14`.

The quickstart configuration lists e.g. a list of Vaadin Routes, and therefore
it's good to generate it during compile time. Unfortunately, at the moment, Maven Jetty plugin can't
do that, see&vote for [Jetty #9497](https://github.com/eclipse/jetty.project/issues/9497).

Workaround is to generate the config file manually. You need to start your app in order for Jetty to
perform the classpath scanning. Don't forget to run the app in production mode, otherwise
the quickstart config file will contain Vaadin dev mode stuff like `DevModeStartupListener`.

```java
public class Main {
public static void main(String[] args) throws Exception {
new VaadinBoot() {
protected void onStarted(@NotNull WebAppContext context) {
context.setAttribute(ExtraXmlDescriptorProcessor.class.getName(), new ExtraXmlDescriptorProcessor());
final String xml = new File("quickstart-web.xml").getAbsolutePath();
try (OutputStream out = new BufferedOutputStream(new FileOutputStream(xml))) {
new QuickStartGeneratorConfiguration().generateQuickStartWebXml(context, out);
}
}
}.withArgs(args).run();
}
}
```

Place the file here: `src/main/resources/webapp/WEB-INF/quickstart-web.xml`. From now on,
Jetty should read the QuickStart config and skip the classpath scanning automatically; however
you can still enforce the QuickStart mode:

```java
public class Main {
public static void main(String[] args) throws Exception {
new VaadinBoot() {
protected WebAppContext createWebAppContext() throws MalformedURLException {
WebAppContext ctx = super.createWebAppContext();
context.setAttribute(QuickStartConfiguration.MODE, QuickStartConfiguration.Mode.QUICKSTART);
return ctx;
}
}.withArgs(args).disableClasspathScanning().run();
}
}
```

## Native

Building a native app with GraalVM is unsupported at the moment. Please see [Issue #10](https://github.com/mvysny/vaadin-boot/issues/10)
for more details.

# Developing Vaadin-Boot

See [CONTRIBUTING](CONTRIBUTING.md)
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import javax.servlet.Servlet;
import java.io.IOException;
import java.net.InetSocketAddress;
import java.net.MalformedURLException;
import java.time.Duration;
import java.util.Objects;

Expand Down Expand Up @@ -64,6 +63,14 @@ public class VaadinBoot {
*/
private boolean openBrowserInDevMode = true;

/**
* If true, no classpath scanning is performed - no servlets nor weblisteners are detected.
* <p></p>
* This will most probably cause Vaadin to not work and throw NullPointerException at <code>VaadinServlet.serveStaticOrWebJarRequest</code>.
* However, it's a good thing to disable this when starting your app with a QuickStart configuration.
*/
private boolean disableClasspathScanning = false;

/**
* Creates the new instance of the Boot launcher.
*/
Expand Down Expand Up @@ -166,6 +173,18 @@ public String getServerURL() {
return "http://" + (hostName != null ? hostName : "localhost") + ":" + port + contextRoot;
}

/**
* If true, no classpath scanning is performed - no servlets nor weblisteners are detected.
* <p></p>
* This will most probably cause Vaadin to not work and throw NullPointerException at <code>VaadinServlet.serveStaticOrWebJarRequest</code>.
* However, it's a good thing to disable this when starting your app with a QuickStart configuration.
*/
@NotNull
public VaadinBoot disableClasspathScanning() {
disableClasspathScanning = true;
return this;
}

// mark volatile: might be accessed by the shutdown hook from a different thread.
private volatile Server server;

Expand Down Expand Up @@ -264,13 +283,14 @@ protected WebAppContext createWebAppContext() throws IOException {
context.setBaseResource(Env.findWebRoot());
context.setContextPath(contextRoot);
context.addServlet(servlet, "/*");
// this will properly scan the classpath for all @WebListeners, including the most important
// com.vaadin.flow.server.startup.ServletContextListeners.
// See also https://mvysny.github.io/vaadin-lookup-vs-instantiator/
// Jetty documentation: https://www.eclipse.org/jetty/documentation/jetty-12/operations-guide/index.html#og-annotations-scanning
context.setAttribute("org.eclipse.jetty.server.webapp.ContainerIncludeJarPattern", ".*\\.jar|.*/classes/.*");
context.setConfigurationDiscovered(true);
context.getServletContext().setExtendedListenerTypes(true);
if (!disableClasspathScanning) {
// this will properly scan the classpath for all @WebListeners, including the most important
// com.vaadin.flow.server.startup.ServletContextListeners.
// See also https://mvysny.github.io/vaadin-lookup-vs-instantiator/
// Jetty documentation: https://www.eclipse.org/jetty/documentation/jetty-12/operations-guide/index.html#og-annotations-scanning
context.setAttribute("org.eclipse.jetty.server.webapp.ContainerIncludeJarPattern", ".*\\.jar|.*/classes/.*");
context.setConfigurationDiscovered(true);
}
return context;
}

Expand Down

0 comments on commit 8bce215

Please sign in to comment.