Jetty embedding revisited
This commit is contained in:
74
container/pom.xml
Normal file
74
container/pom.xml
Normal file
@@ -0,0 +1,74 @@
|
||||
<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>org.jeudego.pairgoth</groupId>
|
||||
<artifactId>engine-parent</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
<artifactId>container</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
<description>Creates a UberJar consisting of all classes needed to start Jetty</description>
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.jetty</groupId>
|
||||
<artifactId>jetty-webapp</artifactId>
|
||||
<version>${jetty.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.jetty</groupId>
|
||||
<artifactId>jetty-annotations</artifactId>
|
||||
<version>${jetty.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.jetty.websocket</groupId>
|
||||
<artifactId>websocket-javax-server</artifactId>
|
||||
<version>${jetty.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.jetty</groupId>
|
||||
<artifactId>jetty-slf4j-impl</artifactId>
|
||||
<version>${jetty.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-shade-plugin</artifactId>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>rebuild-war</id>
|
||||
<phase>package</phase>
|
||||
<goals>
|
||||
<goal>shade</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<createDependencyReducedPom>false</createDependencyReducedPom>
|
||||
<artifactSet>
|
||||
<includes>
|
||||
<include>*:*</include>
|
||||
</includes>
|
||||
</artifactSet>
|
||||
<filters>
|
||||
<filter>
|
||||
<artifact>*:*</artifact>
|
||||
<excludes>
|
||||
<exclude>META-INF/MANIFEST.MF</exclude>
|
||||
<exclude>META-INF/VERSION.txt</exclude>
|
||||
</excludes>
|
||||
</filter>
|
||||
</filters>
|
||||
<transformers>
|
||||
<transformer implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer"/>
|
||||
</transformers>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
@@ -0,0 +1,108 @@
|
||||
//
|
||||
// ========================================================================
|
||||
// Copyright (c) Mort Bay Consulting Pty Ltd and others.
|
||||
// ------------------------------------------------------------------------
|
||||
// All rights reserved. This program and the accompanying materials
|
||||
// are made available under the terms of the Eclipse Public License v1.0
|
||||
// and Apache License v2.0 which accompanies this distribution.
|
||||
//
|
||||
// The Eclipse Public License is available at
|
||||
// http://www.eclipse.org/legal/epl-v10.html
|
||||
//
|
||||
// The Apache License v2.0 is available at
|
||||
// http://www.opensource.org/licenses/apache2.0.php
|
||||
//
|
||||
// You may elect to redistribute this code under either of these licenses.
|
||||
// ========================================================================
|
||||
//
|
||||
|
||||
package org.jeudego.pairgoth.container;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
|
||||
import org.eclipse.jetty.server.Server;
|
||||
import org.eclipse.jetty.util.resource.PathResource;
|
||||
import org.eclipse.jetty.webapp.WebAppContext;
|
||||
|
||||
public class ServerMain
|
||||
{
|
||||
enum OperationalMode
|
||||
{
|
||||
DEV,
|
||||
PROD
|
||||
}
|
||||
|
||||
private Path basePath;
|
||||
|
||||
public static void main(String[] args)
|
||||
{
|
||||
try
|
||||
{
|
||||
new ServerMain().run();
|
||||
}
|
||||
catch (Throwable t)
|
||||
{
|
||||
t.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private void run() throws Throwable
|
||||
{
|
||||
Server server = new Server(8080);
|
||||
|
||||
WebAppContext context = new WebAppContext();
|
||||
context.setContextPath("/");
|
||||
|
||||
switch (getOperationalMode())
|
||||
{
|
||||
case PROD:
|
||||
// Configure as WAR
|
||||
context.setWar(basePath.toString());
|
||||
break;
|
||||
case DEV:
|
||||
// Configuring from Development Base
|
||||
context.setBaseResource(new PathResource(basePath.resolve("src/main/webapp")));
|
||||
// Add webapp compiled classes & resources (copied into place from src/main/resources)
|
||||
Path classesPath = basePath.resolve("target/webapp/WEB-INF/classes");
|
||||
context.setExtraClasspath(classesPath.toAbsolutePath().toString());
|
||||
server.setDumpAfterStart(true);
|
||||
break;
|
||||
default:
|
||||
throw new FileNotFoundException("Unable to configure WebAppContext base resource undefined");
|
||||
}
|
||||
|
||||
server.setHandler(context);
|
||||
|
||||
server.start();
|
||||
server.join();
|
||||
}
|
||||
|
||||
private OperationalMode getOperationalMode() throws IOException
|
||||
{
|
||||
// Property set by jetty.bootstrap.JettyBootstrap
|
||||
String warLocation = System.getProperty("org.eclipse.jetty.livewar.LOCATION");
|
||||
if (warLocation != null)
|
||||
{
|
||||
Path warPath = new File(warLocation).toPath().toRealPath();
|
||||
if (Files.exists(warPath) && Files.isRegularFile(warPath))
|
||||
{
|
||||
this.basePath = warPath;
|
||||
return OperationalMode.PROD;
|
||||
}
|
||||
}
|
||||
|
||||
// We are in development mode, likely building and testing from an IDE.
|
||||
Path devPath = new File("../webapp").toPath().toRealPath();
|
||||
if (Files.exists(devPath) && Files.isDirectory(devPath))
|
||||
{
|
||||
this.basePath = devPath;
|
||||
return OperationalMode.DEV;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
8
container/src/main/resources/jetty-logging.properties
Normal file
8
container/src/main/resources/jetty-logging.properties
Normal file
@@ -0,0 +1,8 @@
|
||||
org.eclipse.jetty.util.log.class=org.eclipse.jetty.util.log.StdErrLog
|
||||
org.eclipse.jetty.LEVEL=INFO
|
||||
|
||||
# Squelch noisy logging
|
||||
org.eclipse.jetty.websocket.jsr356.JsrBasicRemote.LEVEL=WARN
|
||||
|
||||
# org.eclipse.jetty.annotations.LEVEL=DEBUG
|
||||
# org.eclipse.jetty.websocket.LEVEL=DEBUG
|
Reference in New Issue
Block a user