Created
September 14, 2012 03:35
-
-
Save kawasima/3719644 to your computer and use it in GitHub Desktop.
Tomcat Embedded Server
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package net.unit8.starborn.hotpepper; | |
import java.io.File; | |
import org.apache.catalina.core.AprLifecycleListener; | |
import org.apache.catalina.core.StandardServer; | |
import org.apache.catalina.startup.Tomcat; | |
public class EmbeddedServer { | |
public static void main(String[] args) throws Exception { | |
String appBase = new File("src/main/webapp").getAbsolutePath(); | |
Integer port = 8082; | |
String contextPath = "/myapp"; | |
Tomcat tomcat = new Tomcat(); | |
tomcat.setPort(port); | |
tomcat.setBaseDir("."); | |
tomcat.getHost().setAppBase(appBase); | |
StandardServer server = (StandardServer) tomcat.getServer(); | |
AprLifecycleListener listener = new AprLifecycleListener(); | |
server.addLifecycleListener(listener); | |
tomcat.addWebapp(contextPath, appBase); | |
tomcat.start(); | |
tomcat.getServer().await(); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<dependency> | |
<groupId>org.apache.tomcat</groupId> | |
<artifactId>tomcat-catalina</artifactId> | |
<version>7.0.29</version> | |
<scope>test</scope> | |
</dependency> | |
<dependency> | |
<groupId>org.apache.tomcat.embed</groupId> | |
<artifactId>tomcat-embed-core</artifactId> | |
<version>7.0.29</version> | |
<scope>test</scope> | |
</dependency> | |
<dependency> | |
<groupId>org.apache.tomcat</groupId> | |
<artifactId>tomcat-jasper</artifactId> | |
<version>7.0.29</version> | |
<scope>test</scope> | |
</dependency> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment