On Tue, Feb 18, 2020, 14:12 Thad Humphries <thad.humphr...@gmail.com> wrote:

> I am trying to understand how to build and run an app from local with
> Tomcat 9 embedded using Java 8. I've started with this example written for
> Tomcat 7:
>
> https://www.oracle.com/webfolder/technetwork/tutorials/obe/java/basic_app_embedded_tomcat/basic_app-tomcat-embedded.html#overview
>
> I am able to get it to run with Tomcat 9 after a few changes to the pom.xml
> and one addition to the main() method:
>
>     public static void main(String[] args) throws Exception {
>


      String contextPath = "" ;
>

May not be the issue, cause there's other code to consider, but should the
above line be

String contextPath = "/" ;


In the future, you should also check the full stack trace for clues


      String appBase = ".";
>       Tomcat tomcat = new Tomcat();
>       tomcat.setPort(Integer.valueOf(PORT.orElse("8888") ));
>       // next line added for Tomcat 9
>       tomcat.setConnector(tomcat.getConnector());
>
>       tomcat.setHostname(HOSTNAME.orElse("localhost"));
>       tomcat.getHost().setAppBase(appBase);
>       tomcat.addWebapp(contextPath, appBase);
>       tomcat.start();
>       tomcat.getServer().await();
>     }
>
> However although this runs it returns a 404 on /employee. Why?
>
> I've tried variations on other Tomcat 9 examples (such as
> https://nkonev.name/post/101). There main() methods are considerably more
> involved, and I don't follow all that's going on. I've had no success. Some
> don't run, or, in the nkonev example earlier, JSPs aren't processed
> (probably because of "tomcat.setAddDefaultWebXmlToWebapp(false);" but if I
> commnent that out, the Jar won't run).
>
> What's the minimum to get the above main() to serve /employee?
>
>

Reply via email to