tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Woonsan Ko <woon...@apache.org>
Subject Re: unable to serve static files with embedded Tomcat
Date Fri, 19 Apr 2019 17:46:26 GMT
On Fri, Apr 19, 2019 at 1:24 PM Garret Wilson <garret@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...

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-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>

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


Mime
View raw message