Repository navigation
Added Support to launch Jetty 12 from Eclipse. #523
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| Manifest-Version: 1.0 | ||
| Bundle-ManifestVersion: 2 | ||
| Bundle-Name: Jettylauncher | ||
| Bundle-SymbolicName: com.gwtplugins.eclipse.jettylauncher | ||
| Bundle-Version: 4.2.0.qualifier | ||
| Automatic-Module-Name: org.gwtproject.jettylauncher | ||
| Bundle-RequiredExecutionEnvironment: JavaSE-17 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| source.. = src/java/ | ||
| output.. = target/classes | ||
| bin.includes = META-INF/,\ | ||
| . |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,134 @@ | ||
| <project xmlns="http://maven.apache.org/POM/4.0.0" | ||
| xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
| xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
| <modelVersion>4.0.0</modelVersion> | ||
|
|
||
| <parent> | ||
| <groupId>com.gwtplugins.eclipse</groupId> | ||
| <artifactId>trunk</artifactId> | ||
| <version>4.2.0-SNAPSHOT</version> | ||
| <relativePath>../../</relativePath> | ||
| </parent> | ||
|
|
||
| <artifactId>com.gwtplugins.eclipse.jettylauncher</artifactId> | ||
| <version>4.2.0-SNAPSHOT</version> | ||
| <packaging>eclipse-plugin</packaging> | ||
|
|
||
| <properties> | ||
| <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
| <java.version>11</java.version> | ||
| <maven.test.skip>true</maven.test.skip> | ||
| </properties> | ||
|
|
||
| <dependencies> | ||
| <dependency> | ||
| <groupId>org.eclipse.jetty</groupId> | ||
| <artifactId>jetty-server</artifactId> | ||
| <version>12.0.31</version> | ||
| <scope>provided</scope> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>org.eclipse.jetty.ee10</groupId> | ||
| <artifactId>jetty-ee10-servlet</artifactId> | ||
| <version>12.0.31</version> | ||
| <scope>provided</scope> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>org.eclipse.jetty.ee10</groupId> | ||
| <artifactId>jetty-ee10-webapp</artifactId> | ||
| <version>12.0.31</version> | ||
| <scope>provided</scope> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>org.eclipse.jetty.ee8</groupId> | ||
| <artifactId>jetty-ee8-servlet</artifactId> | ||
| <version>12.0.31</version> | ||
| <scope>provided</scope> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>org.eclipse.jetty.ee8</groupId> | ||
| <artifactId>jetty-ee8-webapp</artifactId> | ||
| <version>12.0.31</version> | ||
| <scope>provided</scope> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>org.gwtproject</groupId> | ||
| <artifactId>gwt-dev</artifactId> | ||
| <version>2.12.2</version> | ||
| <scope>provided</scope> | ||
| </dependency> | ||
| </dependencies> | ||
|
|
||
| <build> | ||
| <pluginManagement> | ||
| <plugins> | ||
| <plugin> | ||
| <artifactId>maven-compiler-plugin</artifactId> | ||
| <configuration> | ||
| <source>${java.version}</source> | ||
| <target>${java.version}</target> | ||
| </configuration> | ||
| <executions> | ||
| <execution> | ||
| <id>default-testCompile</id> | ||
| <phase>none</phase> <!-- Deaktiviert das | ||
| Test-Kompilieren --> | ||
| </execution> | ||
| </executions> | ||
| </plugin> | ||
| <plugin> | ||
| <groupId>org.eclipse.tycho</groupId> | ||
| <artifactId>tycho-compiler-plugin</artifactId> | ||
| <version>${tycho.version}</version> | ||
| <configuration> | ||
| <extraClasspathElements> | ||
| <extraClasspathElement> | ||
| <groupId>org.eclipse.jetty</groupId> | ||
| <artifactId>jetty-server</artifactId> | ||
| <version>12.0.36</version> <!-- Version anpassen --> | ||
| </extraClasspathElement> | ||
| <extraClasspathElement> | ||
| <groupId>org.eclipse.jetty.ee8</groupId> | ||
| <artifactId>jetty-ee8-servlet</artifactId> | ||
| <version>12.0.36</version> <!-- Version anpassen --> | ||
| </extraClasspathElement> | ||
| <extraClasspathElement> | ||
| <groupId>org.eclipse.jetty.ee8</groupId> | ||
| <artifactId>jetty-ee8-webapp</artifactId> | ||
| <version>12.0.36</version> | ||
| </extraClasspathElement> | ||
| <extraClasspathElement> | ||
| <groupId>org.eclipse.jetty.ee10</groupId> | ||
| <artifactId>jetty-ee10-servlet</artifactId> | ||
| <version>12.0.36</version> <!-- Version anpassen --> | ||
| </extraClasspathElement> | ||
| <extraClasspathElement> | ||
| <groupId>org.eclipse.jetty.ee10</groupId> | ||
| <artifactId>jetty-ee10-webapp</artifactId> | ||
| <version>12.0.36</version> | ||
| </extraClasspathElement> | ||
| <extraClasspathElement> | ||
| <groupId>org.gwtproject</groupId> | ||
| <artifactId>gwt-dev</artifactId> | ||
| <version>2.12.2</version> | ||
| <exclusions> | ||
| <exclusion> | ||
| <groupId>xml-apis</groupId> | ||
| <artifactId>xml-apis</artifactId> | ||
| </exclusion> | ||
| <exclusion> | ||
| <groupId>xerces</groupId> | ||
| <artifactId>xercesImpl</artifactId> | ||
| </exclusion> | ||
| </exclusions> | ||
| </extraClasspathElement> | ||
| </extraClasspathElements> | ||
| <useProjectDependencies>true</useProjectDependencies> | ||
| <showWarnings>true</showWarnings> | ||
| </configuration> | ||
| </plugin> | ||
| </plugins> | ||
| </pluginManagement> | ||
| </build> | ||
|
|
||
| </project> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| package com.gwtplugins.jettylauncher; | ||
|
|
||
| import java.io.File; | ||
| import java.lang.reflect.Method; | ||
| import java.net.BindException; | ||
|
|
||
| import com.google.gwt.core.ext.ServletContainer; | ||
| import com.google.gwt.core.ext.ServletContainerLauncher; | ||
| import com.google.gwt.core.ext.TreeLogger; | ||
|
|
||
| /** | ||
| * Base class for the Jetty12Launchers. | ||
| */ | ||
| public abstract class AbstractJetty12Launcher extends ServletContainerLauncher { | ||
|
|
||
| @Override | ||
| public ServletContainer start(TreeLogger logger, int port, File appRootDir) throws BindException, Exception { | ||
| // A custom Classloader to separate the classes of the webapp and app server from the rest of the system. | ||
| Jetty12ClassLoader cl = new Jetty12ClassLoader(getJEEVersion()); | ||
| Thread.currentThread().setContextClassLoader(cl); | ||
| //Load and run the Bootstrap in the context of the custom ClassLoader. | ||
| Class<?> bsClass = cl.loadClass(getBootstrapClassname()); | ||
| Class<?>[] types = new Class[2]; | ||
| types[0] = int.class; | ||
| types[1] = File.class; | ||
| Method method = bsClass.getDeclaredMethod("start", types); | ||
| Object[] params = new Object[2]; | ||
| params[0] = port; | ||
| params[1] = appRootDir; | ||
| ServletContainer cont = (ServletContainer) method.invoke(null, params); | ||
| return cont; | ||
| } | ||
|
|
||
| /** | ||
| * The jee Version to load. If jee10 ist activated, the jee8 libraries will not be loaded. | ||
| * @return | ||
| */ | ||
| protected abstract JEEVersion getJEEVersion(); | ||
|
|
||
| /** | ||
| * The name of the class that is used to separate the classloader from other eclipse classes. | ||
| * @return | ||
| */ | ||
| abstract protected String getBootstrapClassname(); | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,96 @@ | ||
| package com.gwtplugins.jettylauncher; | ||
|
|
||
| import java.io.File; | ||
| import org.eclipse.jetty.server.Handler; | ||
| import org.eclipse.jetty.server.Server; | ||
| import org.eclipse.jetty.server.ServerConnector; | ||
| import org.eclipse.jetty.server.handler.InetAccessHandler; | ||
| import org.eclipse.jetty.util.thread.QueuedThreadPool; | ||
|
|
||
| import com.google.gwt.core.ext.ServletContainer; | ||
| import com.google.gwt.core.ext.UnableToCompleteException; | ||
|
|
||
| public abstract class AbstractJetty12ServletContainer extends ServletContainer { | ||
|
|
||
| protected int port; | ||
| protected File appRootDir; | ||
|
|
||
| public AbstractJetty12ServletContainer(int port, File appRootDir) | ||
| { | ||
| super(); | ||
| this.port = port; | ||
| this.appRootDir = appRootDir; | ||
| try | ||
| { | ||
| startServer(port); | ||
| } | ||
| catch (Exception e) | ||
| { | ||
| e.printStackTrace(); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Propagate startup failures. If startup fails, for example because the port is occupied, this catch block prints the exception and still allows the launcher to return a container. Please propagate startup errors through |
||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Create a Thread Pool for the Jetty Server | ||
| * @return | ||
| */ | ||
| protected QueuedThreadPool createThreadPool() | ||
| { | ||
| // Eigenen ThreadPool um Anzahl der Threads kontrollieren zu können | ||
| QueuedThreadPool pool = new QueuedThreadPool(50, 20) | ||
| { | ||
| @Override | ||
| public Thread newThread(Runnable runnable) { | ||
| // Threads markieren | ||
| Thread t = super.newThread(runnable); | ||
| t.setName("Jetty - " + t.getName()); | ||
| return t; | ||
| } | ||
| }; | ||
| return pool; | ||
| } | ||
|
|
||
| /** | ||
| * Starts the Jetty Server on the given Port. | ||
| * @param port | ||
| * @throws Exception | ||
| */ | ||
| public void startServer(int port) throws Exception | ||
| { | ||
| QueuedThreadPool pool = createThreadPool(); | ||
| Server server = new Server(pool); | ||
| ServerConnector connector = new ServerConnector(server); | ||
| connector.setPort(port); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Honor the configured bind address. The launcher does not override |
||
| connector.setIdleTimeout(30000); | ||
| server.addConnector(connector); | ||
| InetAccessHandler ihandler = new InetAccessHandler(); | ||
|
|
||
| Handler.Sequence shandler = createHandler(); | ||
|
|
||
| ihandler.setHandler(shandler); | ||
| server.setHandler(ihandler); | ||
| server.start(); | ||
| } | ||
|
|
||
| /** | ||
| * Create a WebAppContext | ||
| * @return | ||
| */ | ||
| abstract protected Handler.Sequence createHandler(); | ||
|
|
||
| @Override | ||
| public int getPort() | ||
| { | ||
| return port; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Return the actual bound port. With automatic port selection ( |
||
| } | ||
|
|
||
| @Override | ||
| public void refresh() throws UnableToCompleteException | ||
| { | ||
| } | ||
|
|
||
| @Override | ||
| public void stop() throws UnableToCompleteException | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Implement the container lifecycle. |
||
| { | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| package com.gwtplugins.jettylauncher; | ||
|
|
||
| /** | ||
| * JEE Versions. JEE8 for javax.servlet and JEE10 for jakarta.servlet | ||
| */ | ||
| public enum JEEVersion | ||
| { | ||
| JEE8 | ||
| , JEE10 | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Restore the calling thread's context classloader. This changes the context classloader for the caller and leaves it changed on both success and failure. Subsequent work on that thread can then use the Jetty-specific loader unexpectedly. Please save the previous value and restore it in a
finallyblock around bootstrap loading and invocation.