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: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]