Hello again,

Here the code i wrote to start embedded tomcat and load a war-file, and 
following also the output-console.

Maybe: Does a physical web.xml must exist on the filesystem, as i have none and 
use this call <setDefaultWebXml("web.xml")> ? 
Also, in none of all the folders is my web-application extracted as i´m being 
uses with the norml tomcat.

Thanks for any input, Greetings Max


import java.net.URL;
import org.apache.catalina.Connector;
import org.apache.catalina.Context;
import org.apache.catalina.Engine;
import org.apache.catalina.core.StandardContext;
import org.apache.catalina.core.StandardHost;
import org.apache.catalina.startup.Embedded;

public class WebAppServer implements java.io.Closeable {

        private String baseDir;
        private String workDir;
        private boolean started = false;
        private Embedded tomcat = null;

        public WebAppServer() {
                this.baseDir = "c:\\temp";
                System.setProperty("catalina.home", baseDir);
                this.workDir="c:\\juhu";
        }       
        public void close () throws java.io.IOException {
                try  {
                this.tomcat.stop();
                this.tomcat.destroy();
                }
                catch (org.apache.catalina.LifecycleException e) {
                        throw new java.io.IOException();
                }
                                
        }

        public boolean isStarted() {
                return this.started;
        }

        public void start() throws Exception {
        if (!this.isStarted()){                 
        
        this.tomcat = new Embedded();
        this.tomcat.setDebug(0);

        Engine engine = this.tomcat.createEngine();
        engine.setDefaultHost("localhost");
        
        String appBase = this.baseDir +"\\apps";
        StandardHost host =
        (StandardHost)this.tomcat.createHost("localhost", appBase);
              
        host.setWorkDir(this.workDir);

        URL myurl = new URL("file:"+this.baseDir+ "\\mynewwar.war");
        
         host.install("", myurl);
      
        Context context = host.findDeployedApp("");
        ((StandardContext)context).setWorkDir(this.workDir + 
                                              "\\localhost");
        ((StandardContext)context).setDefaultWebXml("web.xml");

        engine.addChild(host);
       
        this.tomcat.addEngine(engine);
        Connector connector = tomcat.createConnector((String)null, 
                                                      8085, false);
        this.tomcat.addConnector(connector);
        this.tomcat.start();
        this.started = true;
        
        }
        else {
                System.out.println("Tomcat already started!");
        }               
    }

        public void stop() throws Exception {
                if (this.tomcat !=null){                
                   this.tomcat.stop();
                   this.tomcat.destroy();
                }
                this.started = false;
        }
}

-----------------------------------------------------------
CONSOLE: Embedded Tomcat starts fine, loads the war-file obviously, but why 
cant i call it and nowhere is a extracted war-file?.. 

27.04.2007 20:52:28 org.apache.catalina.core.StandardHost getDeployer
INFO: Create Host deployer for direct deployment ( non-jmx ) 
27.04.2007 20:52:28 org.apache.catalina.core.StandardHostDeployer install
INFO: Installing web application at context path  from URL 
file:c:/temp/mynewwar.war
27.04.2007 20:52:28 org.apache.catalina.startup.Embedded start
INFO: Starting tomcat server
27.04.2007 20:52:28 org.apache.catalina.core.StandardEngine start
INFO: Starting Servlet Engine: Apache Tomcat/5.0.30
27.04.2007 20:52:28 org.apache.catalina.core.StandardHost start
INFO: XML validation disabled
27.04.2007 20:52:28 org.apache.catalina.startup.ContextConfig defaultConfig
INFO: No default web.xml
27.04.2007 20:52:28 org.apache.coyote.http11.Http11Protocol init
INFO: Initializing Coyote HTTP/1.1 on http-8085
27.04.2007 20:52:28 org.apache.coyote.http11.Http11Protocol start
INFO: Starting Coyote HTTP/1.1 on http-8085



-- 
"Feel free" - 10 GB Mailbox, 100 FreeSMS/Monat ...
Jetzt GMX TopMail testen: http://www.gmx.net/de/go/topmail

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to