package net.usersource.jettyembed;

import org.mortbay.jetty.Connector;
import org.mortbay.jetty.Server;
import org.mortbay.jetty.bio.SocketConnector;
import org.mortbay.jetty.webapp.WebAppContext;

import java.net.URL;
import java.security.ProtectionDomain;

public class Startup {

    private static final int JETTY_PORT = 8080;

    public static void main(String[] args) throws Exception {
        Server server = new Server();
        SocketConnector connector = new SocketConnector();
        connector.setPort(Integer.getInteger("jettyPort", JETTY_PORT));
        server.setConnectors(new Connector[]{connector});

        WebAppContext context = new WebAppContext();
        context.setServer(server);
        context.setContextPath("/");

        ProtectionDomain protectionDomain = Startup.class.getProtectionDomain();
        URL location = protectionDomain.getCodeSource().getLocation();
        context.setWar(location.toExternalForm());

        server.addHandler(context);

        try {
            server.start();
            server.join();
        }
        catch (Exception e) {
            e.printStackTrace();
            System.exit(1);
        }

    }
}

@@ -136,32 +136,83 @@
 ocketConnector;%0A
+import org.mortbay.jetty.webapp.WebAppClassLoader;%0A
 import org.mortb
@@ -304,16 +304,17 @@
 omain;%0A%0A
+%0A
 public c
@@ -376,16 +376,69 @@
  = 8080;
+%0A    private static final int JETTY_MAX_IDLE = 30000;
 %0A%0A    pu
@@ -497,45 +497,8 @@
 n %7B%0A
-        Server server = new Server();
 %0A   
@@ -637,55 +637,236 @@
     
-server.setConnectors(new Connector%5B%5D%7Bconnector%7D
+connector.setMaxIdleTime(Integer.getInteger(%22jettyMaxIdle%22, JETTY_MAX_IDLE));%0A%0A        ProtectionDomain protectionDomain = Startup.class.getProtectionDomain();%0A        URL location = protectionDomain.getCodeSource().getLocation(
 );%0A%0A
@@ -941,21 +941,23 @@
 .set
-Server(server
+ContextPath(%22/%22
 );%0A 
@@ -978,231 +978,279 @@
 .set
-ContextPath(%22/%22);%0A%0A        ProtectionDomain protectionDomain = Startup.class.getProtectionDomain();%0A        URL location = protectionDomain.getCodeSource().getLocation();%0A        context.setWar(location.toExternalForm()
+War(location.toExternalForm());%0A%0A        WebAppClassLoader loader = new WebAppClassLoader( Startup.class.getClassLoader(), context );%0A        context.setClassLoader(loader);%0A%0A        Server server = new Server();%0A        server.setConnectors(new Connector%5B%5D%7Bconnector%7D
 );%0A
-%0A
     
@@ -1264,11 +1264,11 @@
 ver.
-add
+set
 Hand
@@ -1280,16 +1280,60 @@
 ontext);
+%0A        server.setSendServerVersion(false);
 %0A%0A      
@@ -1514,9 +1514,8 @@
 %0A    %7D%0A%7D
-%0A

improve startup code add max timeout