javamaventomcatdevops

404 Error on Tomcat Server even when the WAR file is in the right folder


I am new to maven and building Java projects. So I built a Java project using Maven and copied the WAR file in the webapps folder. The file name is "print" and I copied it in the webapps located at: /opt/homebrew/Cellar/tomcat/10.0.22/libexec/webapps

When I tried to open: http://localhost:8080/print/, I got an HTTP Status 404 – Not Found error.

The path is available in the Tomcat Web Application Manager: enter image description here

The path is available in the Tomcat Web Application Manager:

I tried following some of the guides available here but nothing worked for me. Not sure what's the issue.

Following is pom.xml file:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>

  <groupId>com.springhow.example</groupId>
  <artifactId>hello-world</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <packaging>war</packaging>

  <name>hello-world</name>
  <description>Demo project for Spring Boot</description>

  <parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.3.2.RELEASE</version>
    <relativePath/> <!-- lookup parent from repository -->
  </parent>

  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
    <java.version>1.8</java.version>
  </properties>

  <dependencies>
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-tomcat</artifactId>
      <scope>provided</scope>
    </dependency>
  </dependencies>

  <build>
    <plugins>
      <plugin>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-maven-plugin</artifactId>
      </plugin>
    </plugins>
  </build>
</project>

Solution

  • There is a change for tomcat from version 10 onwards where they started supporting jakarta servlet and are migrating from javax. So I suspect your war will need to be migrated first. For that they have already provided a set of guidelines which you can read about on their official pages.

    For now ,

    1. you can try creating a folder called webapps-javaee parallel to webapps folder.
    2. Copy your war file to this directory.
    3. Delete the war file and the inflated folders out of war files from webapps directory
    4. Start the application again. You will notice that it takes slightly more time for the application to come up. Hopefully, this should solve your problem as it did mine.