Created
May 10, 2014 04:43
-
-
Save jwlyn/e4342411787b459ea9bb to your computer and use it in GitHub Desktop.
最简单的jetty http server
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import org.eclipse.jetty.server.Server; | |
/** The simplest possible Jetty server. | |
*/ | |
public class Main | |
{ | |
public static void main(String[] args) throws Exception | |
{ | |
Server server = new Server(8080); | |
server.start(); | |
server.join(); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="UTF-8"?> | |
<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> | |
<groupId>com.github.xuchaoo</groupId> | |
<artifactId>exe-war</artifactId> | |
<version>1.0-SNAPSHOT</version> | |
<packaging>war</packaging> | |
<name>exe-war</name> | |
<properties> | |
<endorsed.dir>${project.build.directory}/endorsed</endorsed.dir> | |
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | |
<jetty.version>9.2.0.M0</jetty.version> | |
</properties> | |
<dependencies> | |
<!-- <dependency> | |
<groupId>org.eclipse.jetty.aggregate</groupId> | |
<artifactId>jetty-all</artifactId> | |
<version>9.2.0.M0</version> | |
<scope>provided</scope> | |
</dependency> --> | |
<dependency> | |
<groupId>org.eclipse.jetty</groupId> | |
<artifactId>jetty-server</artifactId> | |
<version>${jetty.version}</version> | |
</dependency> | |
<dependency> | |
<groupId>javax.servlet</groupId> | |
<artifactId>servlet-api</artifactId> | |
<version>3.0-alpha-1</version> | |
</dependency> | |
</dependencies> | |
<build> | |
<plugins> | |
<plugin> | |
<groupId>org.apache.maven.plugins</groupId> | |
<artifactId>maven-war-plugin</artifactId> | |
<version>2.3</version> | |
<configuration> | |
<failOnMissingWebXml>false</failOnMissingWebXml> | |
<warName>${project.artifactId}-${project.version}</warName> | |
<archive> | |
<!-- 规定main函数--> | |
<manifest> | |
<mainClass>Main</mainClass> | |
</manifest> | |
</archive> | |
</configuration> | |
<executions> | |
<execution> | |
<id>default-war</id> | |
<phase>package</phase> | |
<goals> | |
<goal>war</goal> | |
</goals> | |
</execution> | |
</executions> | |
</plugin> | |
<!-- 打包之前将Main函数拷贝到war包的根目录下面 --> | |
<plugin> | |
<artifactId>maven-antrun-plugin</artifactId> | |
<executions> | |
<execution> | |
<id>main-class-placement</id> | |
<phase>prepare-package</phase> | |
<configuration> | |
<tasks> | |
<move todir="${project.build.directory}/${project.artifactId}-${project.version}/"> | |
<fileset dir="${project.build.directory}/classes/"> | |
<include name="Main.class" /> | |
</fileset> | |
</move> | |
</tasks> | |
</configuration> | |
<goals> | |
<goal>run</goal> | |
</goals> | |
</execution> | |
</executions> | |
</plugin> | |
<plugin> | |
<groupId>org.apache.maven.plugins</groupId> | |
<artifactId>maven-dependency-plugin</artifactId> | |
<version>2.6</version> | |
<executions> | |
<execution> | |
<id>jetty-classpath</id> | |
<phase>prepare-package</phase> | |
<goals> | |
<goal>unpack-dependencies</goal> | |
</goals> | |
<configuration> | |
<includeGroupIds>org.eclipse.jetty,javax.servlet</includeGroupIds> | |
<excludeArtifactIds>jsp-api,jstl</excludeArtifactIds> | |
<excludes>META-INF/ECLIPSEF.*</excludes> | |
<outputDirectory> | |
${project.build.directory}/${project.artifactId}-${project.version} | |
</outputDirectory> | |
</configuration> | |
</execution> | |
</executions> | |
</plugin> | |
</plugins> | |
</build> | |
</project> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment