forked from liangrui1988/java-admin
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAdminMain.java
More file actions
68 lines (61 loc) · 2.3 KB
/
Copy pathAdminMain.java
File metadata and controls
68 lines (61 loc) · 2.3 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
57
58
59
60
61
62
63
64
65
66
67
68
package com.rui.pro1;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.webapp.WebAppContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class AdminMain {
private static Logger logger = LoggerFactory.getLogger(AdminMain.class);
private static List<String> webappPaths = new ArrayList<>();
public static void main(String[] args) {
int port = 9809;
try {
if (args.length > 0)
port = Integer.parseInt(args[0]);
} catch (Exception ignored) {
ignored.printStackTrace();
}
Server server = new Server(port);
// 关联一个已经存在的上下文 src/main/webapp
//WebAppContext webAppContext = new WebAppContext("webapp", "/main");
WebAppContext webAppContext = new WebAppContext(getWebAppPath(), "/");
//设置描述符位置
webAppContext.setDescriptor("webapp/WEB-INF/web.xml");
// 设置Web内容上下文路径
// webAppContext.setResourceBase("src/main/webapp");
webAppContext.setResourceBase(getWebAppPath());
webAppContext.setDisplayName("main");
//定位项目中class文件的位置
webAppContext.setClassLoader(Thread.currentThread().getContextClassLoader());
webAppContext.setConfigurationDiscovered(true);
webAppContext.setParentLoaderPriority(true);
server.setHandler(webAppContext);
logger.info("ContextPath={}",webAppContext.getContextPath());
logger.info("Descriptor={}",webAppContext.getDescriptor());
logger.info("ResourceBase={}",webAppContext.getResourceBase());
logger.info("BaseResource={}",webAppContext.getBaseResource().toString());
try {
// ServerContainer wscontainer =
// WebSocketServerContainerInitializer.configureContext(webAppContext);
server.start();
server.join();//线程阻塞
} catch (Exception e) {
logger.error("start Exception:{}",e.getMessage());
e.printStackTrace();
}
logger.info("server is start, port is " + port + "............");
}
public static String getWebAppPath() {
webappPaths.add("lib/webapp");
webappPaths.add("src/main/webapp");
for (String webappPath : webappPaths) {
if (new File(webappPath, "WEB-INF/web.xml").exists()) {
logger.warn("find x {}", webappPath);
return webappPath;
}
}
throw new IllegalStateException("not find any webappPath");
}
}