您现在的位置是:首页 >

嵌入式商城 嵌入式Tomcat的实现

火烧 2021-05-25 06:47:28 1051
嵌入式Tomcat的实现   im ort java io File   im ort I etAddre   im ort a ache catali a Co text   im ort a ac

嵌入式Tomcat的实现  

  import java io File;

  import InetAddress;

  import apache catalina Context;

  import apache catalina Engine;

  import apache catalina Host;

  import apache catalina startup Embedded;

  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 String catalinaHomePath String hostName int port)

  {

  ntextPath=contextPath;

  this catalinaHomePath=catalinaHomePath;

  this hostName=hostName;

  this port=port;

  }

嵌入式商城 嵌入式Tomcat的实现

  /**

  * 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);

  engine setDefaultHost(host getName());

  // Create the ROOT context

  Context rootCxt = embedded createContext( contextPath + /webapps/ROOT );

  Context manageCxt = embedded createContext( /manager contextPath+ /webapps/manager );

  //Create your own context

  Context scoreCxt = embedded createContext( /vmm contextPath+ /webapps/vmm );

  rootCxt setPrivileged(true);

  host addChild(rootCxt);

  host addChild(manageCxt);

  host addChild(scoreCxt);

  // Install the assembled container hierarchy

  embedded addEngine(engine);

  // Assemble and install a default HTTP connector

  embedded addConnector(embedded createConnector(InetAddress getByName(null) port false));

  // Start the embedded server

  embedded start();

  }

  /**

  * This method Stops the Tomcat server

  */

  public void stopTomcat() throws Exception {

  // Stop the embedded server

  embedded stop();

  }

  public static void main(String args[]) {

  try {

  String contextPath=(new File( )) getCanonicalPath();

  String catalinaHomePath =(new File( /conf/tomcat )) getCanonicalPath();

  String hostName= localhost ;

  int port = ;

  System out println( contextPath: +contextPath);

  System out println( catalinaHomePath: +catalinaHomePath);

  EmbeddedTomcat tomcat = new EmbeddedTomcat(contextPath catalinaHomePath hostName port);

  tomcat startTomcat();

  }

  catch( Exception e ) {

  e printStackTrace();

  }

  }

lishixinzhi/Article/program/Java/ky/201311/27954  
永远跟党走
  • 如果你觉得本站很棒,可以通过扫码支付打赏哦!

    • 微信收款码
    • 支付宝收款码