Shortest code to start embedded Jetty server

前端 未结 5 1167
醉酒成梦
醉酒成梦 2021-01-30 15:30

I\'m writing some example code where an embedded Jetty server is started. The server must load exactly one servlet, send all requests to the servlet and listen on localhost:80

5条回答
  •  没有蜡笔的小新
    2021-01-30 15:40

    I've written a library, EasyJetty, that makes it MUCH easier to embed Jetty. It is just a thin layer above the Jetty API, really light-weight.

    Your example would look like this:

    import com.athaydes.easyjetty.EasyJetty;
    
    public class Sample {
    
        public static void main(String[] args) {
            new EasyJetty().port(80).servlet("/*", MyApp.class).start();
        }
    
    }
    

提交回复
热议问题