package com.ffbit.maven.solr.jetty;

import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.webapp.WebAppContext;

public class JettyRunner {
    private int port;
    private String contextPath;
    private String warPath;

    private Server server;
    private WebAppContext webapp;

    public JettyRunner(int port, String contextPath, String warPath) {
        this.port = port;
        this.contextPath = contextPath;
        this.warPath = warPath;

        initialize();
    }

    private void initialize() {
        server = new Server(port);
        webapp = new WebAppContext();

        webapp.setWar(warPath);
        webapp.setContextPath(contextPath);

        server.setHandler(webapp);
    }

    public void run() {
        start();

        try {
            server.join();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }

    public void start() {
        try {
            server.start();
        } catch (InterruptedException e) {
            e.printStackTrace();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

}

@@ -954,24 +954,61 @@
 er.start();%0A
+            addSystemShotdownHook();%0A
         %7D ca
@@ -1153,10 +1153,358 @@
 %0A    %7D%0A%0A
+    private void addSystemShotdownHook() %7B%0A        Runtime.getRuntime().addShutdownHook(new Thread() %7B%0A%0A            @Override%0A            public void run() %7B%0A                try %7B%0A                    server.stop();%0A                %7D catch (Exception e) %7B%0A                    e.printStackTrace();%0A                %7D%0A            %7D%0A%0A        %7D);%0A    %7D%0A%0A
 %7D%0A

Stop Jetty properly