Friday, January 11, 2013

Embedded Jetty from eclipse and jar

== Starting Jetty ==

public void start() throws Exception{
        Server server = new Server(port);
       
        WebAppContext context = new WebAppContext();
        context.setOverrideDescriptor("src/main/webapp/WEB-INF/web.xml");
       
        URL weburl = this.getClass().getResource("/src/main/webapp");
        if (weburl == null){
            //running from eclipse
            context.setResourceBase("src/main/webapp");
        }else{
            //running from jar
            context.setResourceBase(weburl.toExternalForm());
        }
       
        context.setContextPath("/");
        context.setParentLoaderPriority(true);

        server.setHandler(context);
       
        server.start();
        server.join();
    }