1

I created a jersey REST application (helloworld) with java+eclipse+tomcat 8.5+maven. The static index.html works fine when I run the project on server. But rest endpoint giving 404.

REST api Hello world class:-

@Path("/hello") public class MyJerseyPage{ @GET @Produces(MediaType.TEXT_HTML) public String sayHtmlHello() { return "Hello from Jersey"; } } 

Rest config class:-

@ApplicationPath("/api") public class RESTConfig extends Application { } 

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>com.nagendrahegde</groupId> <artifactId>therestproject</artifactId> <packaging>war</packaging> <version>0.0.1-SNAPSHOT</version> <name>therestproject 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-client</artifactId> <version>2.26</version> </dependency> <dependency> <groupId>org.glassfish.jersey.core</groupId> <artifactId>jersey-server</artifactId> <version>2.26</version> </dependency> <dependency> <groupId>org.glassfish.jersey.core</groupId> <artifactId>jersey-common</artifactId> <version>2.26</version> </dependency> <dependency> <groupId>org.glassfish.jersey.containers</groupId> <artifactId>jersey-container-servlet</artifactId> <version>2.26</version> </dependency> <dependency> <groupId>org.glassfish.jersey.containers</groupId> <artifactId>jersey-container-servlet-core</artifactId> <version>2.26</version> </dependency> <dependency> <groupId>org.apache.tomcat</groupId> <artifactId>servlet-api</artifactId> <version>6.0.53</version> </dependency> <dependency> <groupId>org.apache.oltu.oauth2</groupId> <artifactId>org.apache.oltu.oauth2.client</artifactId> <version>1.0.0</version> </dependency> <dependency> <groupId>com.google.code.gson</groupId> <artifactId>gson</artifactId> <version>2.3.1</version> </dependency> <dependency> <groupId>com.auth0</groupId> <artifactId>java-jwt</artifactId> <version>3.2.0</version> </dependency> <dependency> <groupId>com.googlecode.jsontoken</groupId> <artifactId>jsontoken</artifactId> <version>1.0</version> </dependency> <dependency> <groupId>org.glassfish.jersey.bundles.repackaged</groupId> <artifactId>jersey-guava</artifactId> <version>2.6</version> </dependency> </dependencies> <build> <finalName>therestproject</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> </web-app> 

Output:-

get on: http://localhost:8080/therestproject/api/hello -> 404 - The origin server did not find a current representation for the target resource or is not willing to disclose that one exists.

The SAME SETUP used to work before, when pom.xml was having below versions of dependencies:-

<dependency> <groupId>com.sun.jersey</groupId> <artifactId>jersey-servlet</artifactId> <version>1.19</version> </dependency> <dependency> <groupId>org.apache.tomcat</groupId> <artifactId>servlet-api</artifactId> <version>6.0.44</version> </dependency> 

IT USED TO WORK! IT STARTED THROWING 404 WHEN I CHANGED POM.XML AND CHANGED THE JERSEY VERSION TO LATEST. I want to keep the latest jersey version since i have to do oauth2 on top of this. Please help.

1 Answer 1

0

This answer might point to a possible solution: add the jersey-ri dependency.

How to set up JAX-RS Application using annotations only (no web.xml)?

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.