package com.github.ltsopensource.startup.admin;

import org.mortbay.jetty.Server;
import org.mortbay.jetty.webapp.WebAppContext;

import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;

/**
 * @author Robert HG (254963746@qq.com) on 9/1/15.
 */
public class JettyContainer {

    public static void main(String[] args) {
        try {
            String confPath = args[0];

            confPath = confPath.trim();

            Properties conf = new Properties();
            InputStream is = new FileInputStream(new File(confPath + "/conf/lts-admin.cfg"));
            conf.load(is);
            String port = conf.getProperty("port");
            if (port == null || port.trim().equals("")) {
                port = "8081";
            }

            Server server = new Server(Integer.parseInt(port));
            WebAppContext webapp = new WebAppContext();
            webapp.setWar(confPath + "/war/lts-admin.war");
            Map<String, String> initParams = new HashMap<String, String>();
            initParams.put("lts.admin.config.path", confPath + "/conf");
            webapp.setInitParams(initParams);
            server.setHandler(webapp);
            server.setStopAtShutdown(true);
            server.start();

            System.out.println("LTS-Admin started. http://" + NetUtils.getLocalHost() + ":" + port + "/index.htm");

        } catch (Exception e) {
            e.printStackTrace();
            System.exit(1);
        }
    }

}

@@ -837,16 +837,204 @@
      %7D%0A%0A
+            String contextPath = conf.getProperty(%22contextPath%22);%0A            if (contextPath == null %7C%7C contextPath.trim().equals(%22%22)) %7B%0A                contextPath = %22/%22;%0A            %7D%0A%0A
         
@@ -1085,24 +1085,24 @@
 Int(port));%0A
-
             
@@ -1201,24 +1201,72 @@
 dmin.war%22);%0A
+            webapp.setContextPath(contextPath);%0A
             
@@ -1556,24 +1556,24 @@
 r.start();%0A%0A
-
             
@@ -1660,16 +1660,58 @@
 + port +
+ (contextPath == %22/%22 ? %22%22 : contextPath) +
  %22/index

support contextPath configuration