一个超级简单的Jetty实例

时间:2022-03-28 21:44:44

Maven:

        <!-- https://mvnrepository.com/artifact/org.mortbay.jetty/jetty -->
        <dependency>
            <groupId>org.mortbay.jetty</groupId>
            <artifactId>jetty</artifactId>
            <version>7.0.0.pre5</version>
        </dependency>

代码:

import org.mortbay.jetty.Server;
import org.mortbay.jetty.handler.ResourceHandler;
import org.mortbay.jetty.servlet.Context;

public class JettySample {
    public static void main(String args[]) throws Exception {
        Server server = new Server(8080);

        Context root = new Context(server,"/");
        root.setResourceBase("./pom.xml");
        root.setHandler(new ResourceHandler());

        server.start();
    }
}