Michelle Crown
Michelle Crown

Reputation: 45

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>

Upvotes: 2

Views: 5349

Answers (2)

Salvador Valencia
Salvador Valencia

Reputation: 1400

My war file runs on my PC on Tomcat 9 and Java 11.
But when running on the server it gives the 404 error. The server has Tomcat 9 but running Java 8.

So even though Tomcat 9 runs on Java 8, you eventually run into errors. Especially with more recent libraries (Grails 5, servlet v.5, etc.)

After I upgraded the server to Java 11 the 404 error went away.

I don't think you need Tomcat 10 and the JavaEE features to fix the issue.

Upvotes: 0

RohithPg
RohithPg

Reputation: 121

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.

Upvotes: 5

Related Questions