On Fri, Apr 19, 2019 at 7:46 PM Woonsan Ko <woon...@apache.org> wrote:
> On Fri, Apr 19, 2019 at 1:24 PM Garret Wilson <gar...@globalmentor.com> > wrote: > > > > Embedding Tomcat 9 (with OpenJDK 11 on Windows 10) I want to serve > > static files from `/foo/bar`. From scouring the web (primarily > > https://stackoverflow.com/a/15235711/421049 ), the documentation, and > > some books (primarily _Apache Tomcat 7_), I have this: > > > > Tomcat tomcat = new Tomcat(); > > tomcat.setPort(8080); > > tomcat.setBaseDir("/foo"); > > I found this before from > > https://stackoverflow.com/questions/48998387/code-works-with-embedded-apache-tomcat-8-but-not-with-9-whats-changed/49011424 > > // Note: make sure that tomcat creates the default connector... > tomcat.getConnector(); > > Worth trying... > That looks correct, and it's easy to spot with the logging (the connector logs that it's starting if it's there). I removed the magic creation of the connector because it was causing far more hacks (where the magic connector had to be removed after its startup). It seemed more normal to have to explicitly create a connector. Rémy > > Woonsan > > > Context ctx = tomcat.addContext("", "/foo/bar"); > > final Wrapper defaultServlet = ctx.createWrapper(); > > defaultServlet.setName("default"); > > > defaultServlet.setServletClass("org.apache.catalina.servlets.DefaultServlet"); > > defaultServlet.addInitParameter("debug", "1"); > > defaultServlet.addInitParameter("listings", "false"); > > defaultServlet.setLoadOnStartup(1); > > ctx.addChild(defaultServlet); > > ctx.addServletMappingDecoded("/", "default"); > > ctx.addWelcomeFile("index.html"); > > tomcat.start(); > > tomcat.getServer().await(); > > > > Everything looks like it starts up: > > > > Apr 19, 2019 2:18:09 PM org.apache.catalina.core.StandardService > > startInternal > > INFO: Starting service [Tomcat] > > Apr 19, 2019 2:18:09 PM org.apache.catalina.core.StandardEngine > > startInternal > > INFO: Starting Servlet engine: [Apache Tomcat/9.0.19] > > Apr 19, 2019 2:18:10 PM > > org.apache.catalina.util.SessionIdGeneratorBase createSecureRandom > > WARNING: Creation of SecureRandom instance for session ID > > generation using [SHA1PRNG] took [281] milliseconds. > > Apr 19, 2019 2:18:10 PM org.apache.catalina.core.ApplicationContext > log > > INFO: default: DefaultServlet.init: input buffer size=2048, output > > buffer size=2048 > > > > But connections to http://localhost:8080/ time out. (I'm pretty sure but > > not positive that I don't have anything blocking this in the firewall.) > > > > Is there some simple thing I'm missing to connect things together? > > > > Thanks, > > > > Garret > > > > P.S. The documentation on the web for the details of this is > > surprisingly sparse. > > > > > > --------------------------------------------------------------------- > > To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org > > For additional commands, e-mail: users-h...@tomcat.apache.org > > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org > For additional commands, e-mail: users-h...@tomcat.apache.org > >