分类:
2008-09-08 18:22:54
import java.io.File;
import java.net.InetAddress;
import org.apache.catalina.Context;
import org.apache.catalina.Engine;
import org.apache.catalina.Host;
import org.apache.catalina.startup.Embedded;
public class EmbeddedTomcat {
private String contextPath = null;
private String hostName=null;
private String catalinaHomePath=null;
private int port=8080;
private Embedded embedded = null;
private Host host = null;
public EmbeddedTomcat(String contextPath,String catalinaHomePath,String hostName,int port)
{
this.contextPath=contextPath;
this.catalinaHomePath=catalinaHomePath;
this.hostName=hostName;
this.port=port;
}
/**
* This method Starts the Tomcat server.
*/
public void startTomcat() throws Exception {
// Create an embedded server
embedded = new Embedded();
Engine engine = null;
// System.setProperty("catalina.home", getPath());
embedded.setCatalinaHome(catalinaHomePath);
// Create an engine
engine = embedded.createEngine();
// Create a default virtual host
host = embedded.createHost(hostName, contextPath+"/webapps");
engine.addChild(host);
[1]