tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Donald Ball <db...@rhoworld.com>
Subject help with embedded tomcat's webapp classloader
Date Fri, 16 Sep 2005 19:53:42 GMT
hey guys. i'm trying out embedding tomcat 5.0 in an swt app that creates 
complex configuration data for a webapp. basically, i'd like the users 
to be able to do a test deploy of the webapp on their own box using 
hsqldb and an embedded tomcat.

my code looks more or less like so:

import org.apache.catalina.*;
import org.apache.catalina.logger.FileLogger;
import org.apache.catalina.realm.MemoryRealm;
import org.apache.catalina.startup.Embedded;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import java.net.InetAddress;

public final class Tomcat {

     private static final Log log = LogFactory.getLog(Tomcat.class);

     private final Embedded embeddedTomcat;
     private final Engine baseEngine;
     private final Host baseHost;
     private final Context rootContext;

     public Tomcat() {
         embeddedTomcat = new Embedded();

         final FileLogger fileLogger = new FileLogger();
         fileLogger.setDirectory(".");
         fileLogger.setPrefix("myTomcat");
         fileLogger.setSuffix(".log");
         fileLogger.setTimestamp(true);
         embeddedTomcat.setLogger(fileLogger);

         final MemoryRealm memoryRealm = new MemoryRealm();
         embeddedTomcat.setRealm(memoryRealm);

         baseEngine = embeddedTomcat.createEngine();
         baseEngine.setName("myEngine");
         baseEngine.setDefaultHost("localhost");

         baseHost = embeddedTomcat.createHost("localhost", "webapps");
         baseEngine.addChild(baseHost);

         rootContext = embeddedTomcat.createContext("", "ROOT");
         baseHost.addChild(rootContext);

         embeddedTomcat.addEngine(baseEngine);

         final Connector httpConnector = 
embeddedTomcat.createConnector((InetAddress)null, 8080, false);
         embeddedTomcat.addConnector(httpConnector);
     }

     public void start() {
         try {
             embeddedTomcat.start();
         } catch (LifecycleException e) {
             log.error("Error starting tomcat", e);
         }
     }

     public void stop() {
         try {
             embeddedTomcat.stop();
         } catch (LifecycleException e) {
             log.error("Error stopping tomcat", e);
         }
     }

}

everything works okay but my webapp fails on initialization, with a 
NoClassDefFoundError on net.sf.hibernate.HibernateException. this is 
somewhat surprising given that hibernate.jar lives in the webapp's 
WEB-INF/lib directory. is there some additional configuration i need to 
do on my embedded Context object to force it to act like a normal tomcat 
webapp Context? do i perhaps need to ensure the webapp directory 
structure is in place before constructing my Tomcat instance? (that is 
to say, are the contents of WEB-INF/lib examined when the Context is 
created and/or added to the Host, or when tomcat is started?)

- donald

---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org


Mime
View raw message