5

I'm trying to deploy a war file in a Tomcat Docker container, but always get 404 Not Found page. I created the Spring Boot project by following Intellij Tutorial, and it works fine on my machine locally.

Here is my Dockerfile:

FROM tomcat:latest
ADD WebTutorial.war /usr/local/tomcat/webapps/ROOT.war

I use the following command to build the image and run container:

$ docker build -t sp-tomcat .
$ docker run -it -p 8080:8080 --name sp-tomcat sp-tomcat

After the container is running, I logged into the container and see the war file has been deployed (I suppose):
enter image description here

Here is the log output:

21-Dec-2021 07:41:35.819 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Server version name:   Apache Tomcat/10.0.14
21-Dec-2021 07:41:35.821 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Server built:          Dec 2 2021 22:01:36 UTC
21-Dec-2021 07:41:35.821 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Server version number: 10.0.14.0
21-Dec-2021 07:41:35.821 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log OS Name:               Linux
21-Dec-2021 07:41:35.822 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log OS Version:            5.10.76-linuxkit
21-Dec-2021 07:41:35.822 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Architecture:          aarch64
21-Dec-2021 07:41:35.822 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Java Home:             /usr/local/openjdk-11
21-Dec-2021 07:41:35.822 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log JVM Version:           11.0.13+8
21-Dec-2021 07:41:35.822 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log JVM Vendor:            Oracle Corporation
21-Dec-2021 07:41:35.822 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log CATALINA_BASE:         /usr/local/tomcat
21-Dec-2021 07:41:35.822 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log CATALINA_HOME:         /usr/local/tomcat
21-Dec-2021 07:41:35.829 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: --add-opens=java.base/java.lang=ALL-UNNAMED
21-Dec-2021 07:41:35.829 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: --add-opens=java.base/java.io=ALL-UNNAMED
21-Dec-2021 07:41:35.829 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: --add-opens=java.base/java.util=ALL-UNNAMED
21-Dec-2021 07:41:35.829 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: --add-opens=java.base/java.util.concurrent=ALL-UNNAMED
21-Dec-2021 07:41:35.829 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: --add-opens=java.rmi/sun.rmi.transport=ALL-UNNAMED
21-Dec-2021 07:41:35.829 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.util.logging.config.file=/usr/local/tomcat/conf/logging.properties
21-Dec-2021 07:41:35.829 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager
21-Dec-2021 07:41:35.829 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djdk.tls.ephemeralDHKeySize=2048
21-Dec-2021 07:41:35.829 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.protocol.handler.pkgs=org.apache.catalina.webresources
21-Dec-2021 07:41:35.829 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dorg.apache.catalina.security.SecurityListener.UMASK=0027
21-Dec-2021 07:41:35.830 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dignore.endorsed.dirs=
21-Dec-2021 07:41:35.830 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dcatalina.base=/usr/local/tomcat
21-Dec-2021 07:41:35.830 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dcatalina.home=/usr/local/tomcat
21-Dec-2021 07:41:35.830 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.io.tmpdir=/usr/local/tomcat/temp
21-Dec-2021 07:41:35.831 INFO [main] org.apache.catalina.core.AprLifecycleListener.lifecycleEvent Loaded Apache Tomcat Native library [1.2.31] using APR version [1.7.0].
21-Dec-2021 07:41:35.832 INFO [main] org.apache.catalina.core.AprLifecycleListener.lifecycleEvent APR capabilities: IPv6 [true], sendfile [true], accept filters [false], random [true], UDS [true].
21-Dec-2021 07:41:35.833 INFO [main] org.apache.catalina.core.AprLifecycleListener.initializeSSL OpenSSL successfully initialized [OpenSSL 1.1.1k  25 Mar 2021]
21-Dec-2021 07:41:35.979 INFO [main] org.apache.coyote.AbstractProtocol.init Initializing ProtocolHandler ["http-nio-8080"]
21-Dec-2021 07:41:35.990 INFO [main] org.apache.catalina.startup.Catalina.load Server initialization in [268] milliseconds
21-Dec-2021 07:41:36.018 INFO [main] org.apache.catalina.core.StandardService.startInternal Starting service [Catalina]
21-Dec-2021 07:41:36.018 INFO [main] org.apache.catalina.core.StandardEngine.startInternal Starting Servlet engine: [Apache Tomcat/10.0.14]
21-Dec-2021 07:41:36.024 INFO [main] org.apache.catalina.startup.HostConfig.deployWAR Deploying web application archive [/usr/local/tomcat/webapps/ROOT.war]
21-Dec-2021 07:41:36.576 INFO [main] org.apache.jasper.servlet.TldScanner.scanJars At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time.
21-Dec-2021 07:41:36.596 INFO [main] org.apache.catalina.startup.HostConfig.deployWAR Deployment of web application archive [/usr/local/tomcat/webapps/ROOT.war] has finished in [572] ms
21-Dec-2021 07:41:36.599 INFO [main] org.apache.coyote.AbstractProtocol.start Starting ProtocolHandler ["http-nio-8080"]
21-Dec-2021 07:41:36.607 INFO [main] org.apache.catalina.startup.Catalina.start Server startup in [617] milliseconds

But there is no luck when I try to view the website through the browser. Can anyone tell me what am I missing?

Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197
billcyz
  • 1,219
  • 2
  • 18
  • 32
  • Anything in the logs? `less /usr/local/tomcat/logs/catalina.out` – Rüdiger Dec 21 '21 at 07:36
  • I've added a screen shot of container's log to the post @Rüdiger – billcyz Dec 21 '21 at 07:48
  • Please [don't upload text as image](https://meta.stackoverflow.com/a/285557/13447). Edit your question to contain all the information in text form - consider to use the editor's formatting options. – Olaf Kock Dec 21 '21 at 07:49
  • Does this answer your question? [Servlet 5.0 JAR throws compile error on javax.servlet.\* but Servlet 4.0 JAR does not](https://stackoverflow.com/questions/64387472/servlet-5-0-jar-throws-compile-error-on-javax-servlet-but-servlet-4-0-jar-does) (hint: try tomcat 9) – Olaf Kock Dec 21 '21 at 07:52
  • No luck, still have the same error @Olaf Kock – billcyz Dec 21 '21 at 08:07
  • In tutorial there is no word about ".war", please refer to: https://spring.io/guides/gs/convert-jar-to-war/ ..the docker part looks trivial/ok – xerx593 Dec 24 '21 at 06:58
  • 1
    You say your application works well locally, but do you deploy it to Tomcat or do you start it as Java application? My guess is: your application does not extend [`SpringBootServletInitializer`](https://docs.spring.io/spring-boot/docs/current/api/org/springframework/boot/web/servlet/support/SpringBootServletInitializer.html) therefore it does not start on Tomcat. – Piotr P. Karwasz Dec 24 '21 at 19:36
  • The example link you shared shows the application to be exported as _.jar_ and not _.war_ file. SpringBoot applications (.jar), do not need explicit tomcat. They run in whatever tomcat version applicable. Its all managed by SpringBoot and no user intervention required. If you do not have any compulsion to run _.war_, things might be easier. – Santosh Dec 30 '21 at 07:38

2 Answers2

9

The problem is the fact that you are trying to run the Spring Boot 2.x application on Tomcat 10 which is not yet supported. One of the biggest changes of the Tomcat 10 was

Migration from Java EE to Jakarta EE as part of the transfer of Java EE to the Eclipse Foundation, the primary package for all implemented APIs has changed from javax.* to jakarta.*. This will almost certainly require code changes to enable applications to migrate from Tomcat 9 and earlier to Tomcat 10 and later.

So all of the APIs which are used by Spring Framework are based on the older javax.* and new jakarta.* will be supported in Spring Framework 6 and Spring Boot 3 late 2022 )) More details here

What you need to do is just adjust the Dockerfile to run the application of the Tomcat 9. This one will work if you are on Java 17

FROM tomcat:9.0-jre17-temurin
ADD WebTutorial.war /usr/local/tomcat/webapps/ROOT.war
Babl
  • 7,446
  • 26
  • 37
  • Actually the first _milestone_ releases of Spring 6 were published mid-December (cf. [announcement](https://spring.io/blog/2021/12/16/spring-framework-6-0-m1-released)). The final versions are still due Q4 2022. – Piotr P. Karwasz Dec 30 '21 at 08:13
0

i had similar requirement to migrate from tomcat 9 to tomcat 10 with spring 2.2.4 (java 8), as we know tomcat 9 is supported with java EE and tomcat 10 onwards JAKARATA EE api.

so only thing as of now we can do is migrate using apache migration tool.

Step 1: after building the war file that is compatable with tomcat 9.

Step 2: download the jar https://dlcdn.apache.org/tomcat/jakartaee-migration/v1.0.0/binaries/jakartaee-migration-1.0.0-shaded.jar copy to some folder

Step 3: run the following the command.

java  -jar jakartaee-migration-1.0.0-shaded.jar old.war new.war

Note : required class are made compatible with the above tool.

Step 4: done. deploy the new.war to tomcat 10 webapps folder.

may be this is helpful.

  • alternative way your web application should be placed in the Host legacyAppBase folder (by default named webapps-javaee) and they will be converted to an equivalent Jakarta EE web application in the Host appBase folder (by default named webapps). – Shashanka Mar 21 '22 at 11:13