On 13/05/2010 07:23, jerryli51 wrote:
>
> I'm trying to use tomcat 6.0.26, when I invoked start, it just quit silently
> instead of waiting there for http request. Does anyone have ideas?
>
> package mytest;
>
> import java.io.File;
> import java.io.IOException;
> import java.net.InetAddress;
> import java.net.InetSocketAddress;
> import java.net.MalformedURLException;
> import java.net.UnknownHostException;
> import java.util.Properties;
>
>
> import org.apache.catalina.Context;
> import org.apache.catalina.Engine;
> import org.apache.catalina.Host;
> import org.apache.catalina.LifecycleException;
> import org.apache.catalina.core.StandardContext;
> import org.apache.catalina.loader.WebappLoader;
> import org.apache.catalina.realm.MemoryRealm;
> import org.apache.catalina.startup.Embedded;
>
> import org.apache.log4j.Logger;
>
> public class EmbedWebServer {
>
> private static final Logger logger =
> Logger.getLogger(EmbedWebServer.class);
>
> public static void main(String[] args) {
> try {
> new EmbedWebServer();
> } catch (Exception t) {
> t.printStackTrace();
> }
>
> }
>
> private Embedded tomcat;
>
> private String catalinaHome;
>
> private String projectHome;
>
> public EmbedWebServer() {
> initConf();
>
> tomcat = new Embedded();
>
> tomcat.setName("Catalina");
> Engine engine = tomcat.createEngine();
>
> engine.setDefaultHost("localhost");
>
> Host host = tomcat.createHost("localhost", projectHome);
> Context ctx = tomcat.createContext (
> "/", "mywebapp");
> ctx.setReloadable(true);
> ((StandardContext)
> ctx).setWorkDir(System.getProperty("java.io.tmpdir") +
> "/jakarta-tomcat/work");
>
> host.addChild(ctx);
>
> engine.addChild(host);
> engine.setName("Catalina");
>
> tomcat.addEngine(engine);
>
> tomcat.addConnector(tomcat.createConnector((java.net.InetAddress) null,
> 8080, false));
>
> registerShutdownHook();
> try {
>
> tomcat.start();
> } catch (Exception e) {
> logger.error(e);
> e.printStackTrace();
> throw new RuntimeException(e);
> }
>
> }
>
> private void initConf() {
> Properties properties = new Properties();
> try {
> properties.load(EmbedWebServer.class
>
> .getResourceAsStream("/tomcat-conf.properties"));
> catalinaHome = properties.getProperty("catalina.home");
>
> File f = new File(".");
> projectHome = f.getAbsolutePath();
> } catch (IOException e) {
> throw new RuntimeException(e);
> }
> }
>
> private void registerShutdownHook() {
> Runtime.getRuntime().addShutdownHook(new Thread() {
> @Override
> public void run() {
> try {
> tomcat.stop();
> } catch (LifecycleException e) {
> throw new RuntimeException(e);
> }
> }
> });
> }
>
> }
>
I got the following stacktrace, with an empty "mywebapp" and an empty
"tomcat-conf.properties".
Any clues as to what's inside them?
p
WARNING: Error registering contexts
java.lang.NullPointerException
at
org.apache.catalina.connector.MapperListener.registerHost(MapperListener.java:332)
at
org.apache.catalina.connector.MapperListener.init(MapperListener.java:129)
at org.apache.catalina.connector.Connector.start(Connector.java:1146)
at org.apache.catalina.startup.Embedded.start(Embedded.java:832)
at mytest.EmbedWebServer.<init>(EmbedWebServer.java:60)
at mytest.EmbedWebServer.main(EmbedWebServer.java:20)
signature.asc
Description: OpenPGP digital signature
