This repository has been archived by the owner on Jan 30, 2019. It is now read-only.
/
AppJettyRunner.java
56 lines (43 loc) · 1.86 KB
/
AppJettyRunner.java
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 demo.app.run;
import demo.app.init.WebAppInitializer;
import org.eclipse.jetty.annotations.AnnotationConfiguration;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.util.ConcurrentHashSet;
import org.eclipse.jetty.webapp.Configuration;
import org.eclipse.jetty.webapp.WebAppContext;
import org.springframework.web.WebApplicationInitializer;
import java.util.concurrent.ConcurrentHashMap;
public class AppJettyRunner {
public static void main(String[] args) throws Exception {
new AppJettyRunner().startExploded();
}
private void startExploded() throws Exception {
Server server = new Server(8080);
server.setHandler(webAppContext());
server.start();
server.join();
}
private WebAppContext webAppContext() {
WebAppContext context = new WebAppContext();
context.setResourceBase("src/main/webapp");
context.setContextPath("/");
context.setParentLoaderPriority(true);
context.setConfigurations(new Configuration[] { webAppAnnotationConfiguration() });
return context;
}
private AnnotationConfiguration webAppAnnotationConfiguration() {
return new AnnotationConfiguration() {
@Override
public void preConfigure(WebAppContext context) throws Exception {
context.setAttribute(CLASS_INHERITANCE_MAP, webAppInitializerClassNameMap());
}
};
}
private ConcurrentHashMap<String, ConcurrentHashSet<String>> webAppInitializerClassNameMap() {
ConcurrentHashSet<String> set = new ConcurrentHashSet<String>();
set.add(WebAppInitializer.class.getName());
ConcurrentHashMap<String, ConcurrentHashSet<String>> map = new ConcurrentHashMap<String, ConcurrentHashSet<String>>();
map.put(WebApplicationInitializer.class.getName(), set);
return map;
}
}