Skip to content

Commit fcda7bd

Browse files
committed
use vaadin boot
1 parent dbc03be commit fcda7bd

File tree

5 files changed

+12
-122
lines changed

5 files changed

+12
-122
lines changed

Diff for: .github/workflows/maven.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ jobs:
88
strategy:
99
matrix:
1010
os: [ubuntu-latest, macos-latest]
11-
java: [1.8, 11, 17]
11+
java: [11, 17]
1212

1313
runs-on: ${{ matrix.os }}
1414

Diff for: README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
# Vaadin 14 npm Polymer 3 running in Embedded Jetty
55

66
A demo project showing the possibility of running a Vaadin 14 app from an
7-
embedded Jetty, as a simple `main()` method.
7+
embedded Jetty, as a simple `main()` method. Uses [Vaadin Boot](https://github.com/mvysny/vaadin-boot).
88

99
Both the development and production modes are supported. Also, the project
1010
demoes packaging itself both into a flatten uberjar and a zip file containing

Diff for: pom.xml

+7-39
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,13 @@
1010
<packaging>jar</packaging>
1111

1212
<properties>
13-
<maven.compiler.source>1.8</maven.compiler.source>
14-
<maven.compiler.target>1.8</maven.compiler.target>
13+
<maven.compiler.source>11</maven.compiler.source>
14+
<maven.compiler.target>11</maven.compiler.target>
1515
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
1616
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
1717
<failOnMissingWebXml>false</failOnMissingWebXml>
1818

1919
<vaadin.version>14.8.20</vaadin.version>
20-
<!-- don't use Jetty 10 - requres Java 11
21-
don't use Jetty 11+ - uses jakarta.Servlet instead of javax.Servlet which makes it incompatible with Vaadin -->
22-
<jetty.version>9.4.48.v20220622</jetty.version>
2320
</properties>
2421

2522
<repositories>
@@ -74,6 +71,11 @@
7471
</exclusion>
7572
</exclusions>
7673
</dependency>
74+
<dependency>
75+
<groupId>com.github.mvysny.vaadin-boot</groupId>
76+
<artifactId>vaadin-boot</artifactId>
77+
<version>10.0</version>
78+
</dependency>
7779

7880
<!-- Added to provide logging output as Vaadin uses -->
7981
<!-- the unbound SLF4J no-operation (NOP) logger implementation -->
@@ -82,40 +84,6 @@
8284
<artifactId>slf4j-simple</artifactId>
8385
</dependency>
8486

85-
<dependency>
86-
<groupId>javax.servlet</groupId>
87-
<artifactId>javax.servlet-api</artifactId>
88-
<version>4.0.1</version>
89-
</dependency>
90-
91-
<!-- Embedded Jetty dependencies -->
92-
<dependency>
93-
<groupId>org.eclipse.jetty</groupId>
94-
<artifactId>jetty-continuation</artifactId>
95-
<version>${jetty.version}</version>
96-
</dependency>
97-
<dependency>
98-
<groupId>org.eclipse.jetty</groupId>
99-
<artifactId>jetty-server</artifactId>
100-
<version>${jetty.version}</version>
101-
</dependency>
102-
<dependency>
103-
<groupId>org.eclipse.jetty.websocket</groupId>
104-
<artifactId>websocket-server</artifactId>
105-
<version>${jetty.version}</version>
106-
</dependency>
107-
<dependency>
108-
<groupId>org.eclipse.jetty.websocket</groupId>
109-
<artifactId>javax-websocket-server-impl</artifactId>
110-
<version>${jetty.version}</version>
111-
<exclusions>
112-
<exclusion>
113-
<groupId>javax.websocket</groupId>
114-
<artifactId>javax.websocket-client-api</artifactId>
115-
</exclusion>
116-
</exclusions>
117-
</dependency>
118-
11987
<!-- Fast Vaadin unit-testing with Karibu-Testing: https://github.com/mvysny/karibu-testing -->
12088
<dependency>
12189
<groupId>com.github.mvysny.kaributesting</groupId>

Diff for: src/main/java/com/vaadin/starter/skeleton/Main.java

+2-81
Original file line numberDiff line numberDiff line change
@@ -1,93 +1,14 @@
11
package com.vaadin.starter.skeleton;
22

3-
import com.vaadin.flow.server.VaadinServlet;
4-
import com.vaadin.flow.server.startup.ServletContextListeners;
5-
import org.eclipse.jetty.annotations.AnnotationConfiguration;
6-
import org.eclipse.jetty.server.Server;
7-
import org.eclipse.jetty.util.resource.Resource;
8-
import org.eclipse.jetty.webapp.*;
9-
import org.eclipse.jetty.websocket.jsr356.server.deploy.WebSocketServerContainerInitializer;
3+
import com.github.mvysny.vaadinboot.VaadinBoot;
104
import org.jetbrains.annotations.NotNull;
115

12-
import java.net.MalformedURLException;
13-
import java.net.URL;
14-
156
/**
167
* Run {@link #main(String[])} to launch your app in Embedded Jetty.
178
* @author mavi
189
*/
1910
public final class Main {
20-
21-
private static Server server;
22-
2311
public static void main(@NotNull String[] args) throws Exception {
24-
start(args);
25-
server.join();
26-
}
27-
28-
public static void start(@NotNull String[] args) throws Exception {
29-
// detect&enable production mode
30-
if (isProductionMode()) {
31-
// fixes https://github.com/mvysny/vaadin14-embedded-jetty/issues/1
32-
System.out.println("Production mode detected, enforcing");
33-
System.setProperty("vaadin.productionMode", "true");
34-
}
35-
36-
final WebAppContext context = new WebAppContext();
37-
context.setBaseResource(findWebRoot());
38-
context.setContextPath("/");
39-
context.addServlet(VaadinServlet.class, "/*");
40-
context.setAttribute("org.eclipse.jetty.server.webapp.ContainerIncludeJarPattern", ".*\\.jar|.*/classes/.*");
41-
context.setConfigurationDiscovered(true);
42-
context.getServletContext().setExtendedListenerTypes(true);
43-
context.addEventListener(new ServletContextListeners());
44-
WebSocketServerContainerInitializer.initialize(context); // fixes IllegalStateException: Unable to configure jsr356 at that stage. ServerContainer is null
45-
46-
int port = 8080;
47-
if (args.length >= 1) {
48-
port = Integer.parseInt(args[0]);
49-
}
50-
server = new Server(port);
51-
server.setHandler(context);
52-
final Configuration.ClassList classlist = Configuration.ClassList.setServerDefault(server);
53-
classlist.addBefore(JettyWebXmlConfiguration.class.getName(), AnnotationConfiguration.class.getName());
54-
server.start();
55-
56-
System.out.println("\n\n=================================================\n\n" +
57-
"Please open http://localhost:" + port + " in your browser\n\n" +
58-
"If you see the 'Unable to determine mode of operation' exception, just kill me and run `mvn -C clean package`\n\n" +
59-
"=================================================\n\n");
60-
}
61-
62-
public static void stop() throws Exception {
63-
server.stop();
64-
server = null;
65-
}
66-
67-
private static boolean isProductionMode() {
68-
final String probe = "META-INF/maven/com.vaadin/flow-server-production-mode/pom.xml";
69-
final ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
70-
return classLoader.getResource(probe) != null;
71-
}
72-
73-
@NotNull
74-
private static Resource findWebRoot() throws MalformedURLException {
75-
// don't look up directory as a resource, it's unreliable: https://github.com/eclipse/jetty.project/issues/4173#issuecomment-539769734
76-
// instead we'll look up the /webapp/ROOT and retrieve the parent folder from that.
77-
final URL f = Main.class.getResource("/webapp/ROOT");
78-
if (f == null) {
79-
throw new IllegalStateException("Invalid state: the resource /webapp/ROOT doesn't exist, has webapp been packaged in as a resource?");
80-
}
81-
final String url = f.toString();
82-
if (!url.endsWith("/ROOT")) {
83-
throw new RuntimeException("Parameter url: invalid value " + url + ": doesn't end with /ROOT");
84-
}
85-
System.err.println("/webapp/ROOT is " + f);
86-
87-
// Resolve file to directory
88-
URL webRoot = new URL(url.substring(0, url.length() - 5));
89-
System.err.println("WebRoot is " + webRoot);
90-
return Resource.newResource(webRoot);
12+
new VaadinBoot().withArgs(args).run();
9113
}
9214
}
93-

Diff for: src/main/resources/simplelogger.properties

+1
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ org.slf4j.simpleLogger.defaultLogLevel = info
22
org.slf4j.simpleLogger.showDateTime = true
33
org.slf4j.simpleLogger.dateTimeFormat = yyyy-MM-dd HH:mm:ss.SSS
44
org.slf4j.simpleLogger.log.org.atmosphere = warn
5+
org.slf4j.simpleLogger.log.org.eclipse.jetty = warn

0 commit comments

Comments
 (0)