import java
import
import org
import org
import org
import org
public class EmbeddedTomcat {
private String contextPath = null;
private String hostName=null;
private String catalinaHomePath=null;
private int port=
private Embedded embedded = null;
private Host host = null;
public EmbeddedTomcat(String contextPath
{
ntextPath=contextPath;
this
this
this
}
/**
* This method Starts the Tomcat server
*/
public void startTomcat() throws Exception {
// Create an embedded server
embedded = new Embedded();
Engine engine = null;
// System
embedded
// Create an engine
engine = embedded
// Create a default virtual host
host = embedded
engine
engine
// Create the ROOT context
Context rootCxt = embedded
Context manageCxt = embedded
//Create your own context
Context scoreCxt = embedded
rootCxt
host
host
host
// Install the assembled container hierarchy
embedded
// Assemble and install a default HTTP connector
embedded
// Start the embedded server
embedded
}
/**
* This method Stops the Tomcat server
*/
public void stopTomcat() throws Exception {
// Stop the embedded server
embedded
}
public static void main(String args[]) {
try {
String contextPath=(new File(
String catalinaHomePath =(new File(
String hostName=
int port =
System
System
EmbeddedTomcat tomcat = new EmbeddedTomcat(contextPath
tomcat
}
catch( Exception e ) {
e
}
}
}
From:http://tw.wingwit.com/Article/program/Java/ky/201311/27954.html