JettyContainer.java
1.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
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";
}
String contextPath = conf.getProperty("contextPath");
if (contextPath == null || contextPath.trim().equals("")) {
contextPath = "/";
}
Server server = new Server(Integer.parseInt(port));
WebAppContext webapp = new WebAppContext();
webapp.setWar(confPath + "/war/lts-admin.war");
webapp.setContextPath(contextPath);
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 + (contextPath == "/" ? "" : contextPath) + "/index.htm");
} catch (Exception e) {
e.printStackTrace();
System.exit(1);
}
}
}