Pārlūkot izejas kodu

Add Main with embedded Tomcat to start project

Craig Walls 13 gadus atpakaļ
vecāks
revīzija
c64215d510
2 mainītis faili ar 39 papildinājumiem un 3 dzēšanām
  1. 7
    3
      start/build.gradle
  2. 32
    0
      start/src/main/java/hello/Main.java

+ 7
- 3
start/build.gradle Parādīt failu

@@ -1,14 +1,18 @@
1 1
 apply plugin: 'java'
2
-apply plugin: 'jetty'
3 2
 apply plugin: 'eclipse-wtp'
4 3
 apply plugin: 'idea'
4
+apply plugin: 'application'
5
+
6
+mainClassName = "hello.Main"
5 7
 
6 8
 repositories { mavenCentral() }
7 9
 
8 10
 dependencies {
9 11
 	compile "org.springframework:spring-webmvc:3.2.2.RELEASE"
10
-	compile "com.fasterxml.jackson.core:jackson-core:2.1.4"
11
-	providedCompile "javax.servlet:servlet-api:2.5"
12
+	compile "com.fasterxml.jackson.core:jackson-databind:2.1.4"
13
+	compile "org.apache.tomcat:tomcat-catalina:7.0.39"
14
+	compile "org.apache.tomcat.embed:tomcat-embed-core:7.0.39"
15
+	compile "org.apache.tomcat:tomcat-jasper:7.0.39"
12 16
 }
13 17
 
14 18
 task wrapper(type: Wrapper) {

+ 32
- 0
start/src/main/java/hello/Main.java Parādīt failu

@@ -0,0 +1,32 @@
1
+package hello;
2
+
3
+import java.util.HashSet;
4
+
5
+import org.apache.catalina.Context;
6
+import org.apache.catalina.core.AprLifecycleListener;
7
+import org.apache.catalina.core.StandardServer;
8
+import org.apache.catalina.startup.Tomcat;
9
+import org.springframework.web.SpringServletContainerInitializer;
10
+
11
+public class Main {
12
+
13
+	public static void main(String[] args) throws Exception {
14
+		Tomcat tomcat = new Tomcat();
15
+		tomcat.setPort(8080);
16
+		tomcat.setBaseDir(".");
17
+		tomcat.getHost().setAppBase("/");
18
+
19
+		// Add AprLifecycleListener
20
+		StandardServer server = (StandardServer)tomcat.getServer();
21
+		AprLifecycleListener listener = new AprLifecycleListener();
22
+		server.addLifecycleListener(listener);
23
+
24
+		Context context = tomcat.addWebapp("/", "/");
25
+		HashSet<Class<?>> classes = new HashSet<Class<?>>();
26
+		classes.add(HelloWorldWebAppInitializer.class);
27
+		context.addServletContainerInitializer(new SpringServletContainerInitializer(), classes);
28
+		tomcat.start();
29
+		tomcat.getServer().await();
30
+	}
31
+	
32
+}