On Mar 14, 2013, at 4:25 PM, Konstantin Kolinko wrote: > 2013/3/15 Nick Williams <nicho...@nicholaswilliams.net>: >> >> On Mar 14, 2013, at 2:56 PM, Nick Williams wrote: >> >>> Using a variety of tutorials I found online and the documentation for >>> o.a.c.startup.Tomcat, I created the following main method to start up an >>> embedded Tomcat. I'm using 7.0.37 Tomcat JARs. >>> >>> public static void main(String... arguments) throws Exception >>> { >>> Tomcat tomcat = new Tomcat(); >>> tomcat.setBaseDir(".basedir"); >>> tomcat.setPort(8973); >>> tomcat.enableNaming(); >>> tomcat.init(); >>> tomcat.start(); >>> >>> System.out.println("X: " + >>> tomcat.getConnector().getService().getContainer()); >>> >>> tomcat.getServer().await(); >>> } >>> >>> The System.out.println is for debugging purposes, because I'm getting a >>> NullPointerException. Obviously I'm doing something wrong, because about an >>> hour of Googling turned up precisely zero results of anyone who's getting a >>> NullPointerException in MapperListener#findDefaultHost. For some reason, it >>> looks like a Container is never created. What gives? Here's the full output >>> of running the JAR file: > > > Why do you expect that default "Host" exist, if you have not created > one, nor asked for one, nor deployed a web application, all of them > auto-create it if it is missing. > > There may be different implementations of a Host. It needs > configuration (name). Thus initially there is none created. > > Calling tomcat.getHost() should be enough. > > Note, that Tomcat needs a default web application (aka context with > path "", aka ROOT) for certain features (error reporting) to work > properly.
I understand what I was doing wrong, now. I was trying to take any web application errors out of the picture so that I could solve any other problems I was having first. I didn't realize that you couldn't start normally if you didn't have any applications to deploy, so I was actually causing more problems by removing the adding of my web application. I don't need tomcat.getService().setContainer(tomcat.getEngine()) anymore now that I'm calling addWebapp on a proper web application. Mark, my application successfully deploys to the ROOT context in the embedded Tomcat and a test servlet (/healthCheck) starts up properly and requests to it resolve properly. However, my WebSocket endpoints were not working. I was getting 404 errors for any requests to them. It tracked it down to missing service providers. The following files are missing from the org.apache.tomcat.embed:tomcat-embed-core artifact: META-INF/services/javax.servlet.ServletContainerInitializer META-INF/services/javax.websocket.ContainerProvider META-INF/services/javax.websocket.server.ServerContainerProvider META-INF/services/javax.websocket.server.ServerEndpointConfig.Configurator When I added those to my uber-jar embedded JAR file, WebSockets started working properly. So, looks like something about the way that artifact is built is omitting those files accidentally. I can file a bug about this if you need me to. --------------------------------------------------------------------- To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org For additional commands, e-mail: users-h...@tomcat.apache.org