Viktor Todorov
Viktor Todorov

Reputation: 390

Eclipse - Maven project with Tomcat receives 404 Error

I go over the internet to figure it out why I receive 404 I tried almost all solutions and didn't help. I have:

  1. Eclipse Photom
  2. Tomcat 9
  3. Java version 1.8
  4. Maven project using Jersey 2.27

When I hit http://localhost:8080/Test/rest/testservice I got 404 "Description The origin server did not find a current representation for the target resource or is not willing to disclose that one exists."

POM.XML

<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/maven-v4_0_0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>Test</groupId>
  <artifactId>com.test</artifactId>
  <packaging>war</packaging>
  <version>0.0.1-SNAPSHOT</version>
  <name>com.test Maven Webapp</name>
  <url>http://maven.apache.org</url>
<dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>3.8.1</version>
      <scope>test</scope>
    </dependency>
	<dependency>
		<groupId>org.glassfish.jersey.core</groupId>
		<artifactId>jersey-server</artifactId>
		<version>2.27</version>
	</dependency>
	<dependency>
		<groupId>org.glassfish.jersey.containers</groupId>
		<artifactId>jersey-container-servlet</artifactId>
		<version>2.27</version>
	</dependency>
	<dependency>
		<groupId>org.glassfish.jersey.inject</groupId>
		<artifactId>jersey-hk2</artifactId>
		<version>2.27</version>
	</dependency>
    <dependency> 
   		<groupId>javax.xml.bind</groupId> 
   		<artifactId>jaxb-api</artifactId> 
  		<version>2.2.6</version> 
</dependency>
    
  </dependencies>
  <build>
  <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.1</version>
            <configuration>
                <source>1.8</source>
                <target>1.8</target>
            </configuration>
        </plugin>
    </plugins>
    <finalName>com.test</finalName>
  </build>
</project>

WEB.XML

<!DOCTYPE web-app PUBLIC
 "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
 "http://java.sun.com/dtd/web-app_2_3.dtd" >

<web-app>
  <display-name>Archetype Created Web Application</display-name>
  <servlet>
<servlet-name>Test Jersey Service</servlet-name>

<servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
	<init-param>
	<param-name>jersey.config.server.provider.packages</param-name>
	<param-value>com.test</param-value>
	</init-param>
	<load-on-startup>1</load-on-startup>
</servlet>

<servlet-mapping>
	<servlet-name>Test Jersey Service </servlet-name>
	<url-pattern>/rest/*</url-pattern>
</servlet-mapping>

</web-app>

PROJECT STRUCTURE AND JAVA CLASS

PROJECT STRUCTURE AND JAVA CLASS

  1. I Have added in Deployment Assembly -> Maven Dependencies also

Upvotes: 1

Views: 3279

Answers (1)

Viktor Todorov
Viktor Todorov

Reputation: 390

I solved it. So if anyone experience problems with 404 even the fact that you did everything right then double check these steps:

  1. Always save (CTR + S) pom.xml and web.xml when you make any kind of modifications

  2. Replace index.jsp with index.html

  3. Right click the project go to Maven -> Update Project

  4. Right click the project go to Run as -> Run on Server (if I run it manually it doesn't work, but when I go from run as it is working correctly)

I have created a tutorial with step by step. If anyone wanted please contact me.

Upvotes: 2

Related Questions