I have lost the ability to develop/test my RESTful JAX-RS web services when running in Eclipse, using Tomcat 9.0.31. When I start up tomcat inside eclipse and try and hit any one of a number of JAX-RS wed services I have written, I receive a 404 error. For this type of testing I generally use Fiddler to hit the service URL
I have read through a number of posts here on SO including, but not limited to:
- JAX-RS on TomCat always returns 404
- 404 on JAX-RS on Tomcat, MBeans?
- Jersey JAX-RS application returns 404
and more. Most of the responses appear to be for servlet 2.5 and earlier and refer to using the servlet description in the web.xml.
My more recent services are all annotated, and I do not need to add anything to the web.xml.
My web.xml starts out with
<?xml version="1.0" encoding="UTF-8"?>
<web-app
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:jsp="http://java.sun.com/xml/ns/javaee/jsp"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd"
version="4.0">
The things I have tried are numerous. For instance, I was using OpenJDK 13 as my java SDK, so I changed my default JRE in eclipse to my OpenJDK 8 (1.8) which did not help. I've done a number of project clean/builds, and maven project updates.
One thing I read and already knew of was setting the metadata-complete
attribute to false in the web.xml header. That was already set, so I removed it. Still no good. I tried upgrading my Jersey Bundle dependency version in my pom, no good.
I did try overriding the getClasses() method
@Override
public Set< Class< ? > > getClasses() {
final Set< Class< ? > > returnValue = new HashSet< Class< ? > >();
returnValue.add( TestApi.class );
return returnValue;
}
which also did not work. Note that after each change I stopped and started my Tomcat server inside Eclipse.
So here is the pertinent information:
Eclipse project facets:
- Dynamic Web Module 4.0
- Java 1.8
- JavaScript 1.0
I've already posted the web.xml header above
pom.xml:
<dependency>
<groupId>org.glassfish.jersey.bundles</groupId>
<artifactId>jaxrs-ri</artifactId>
<version>2.32</version> <-- Note I was using version 2.29 this is the version I upgraded too.
</dependency>
Application Subclass:
package com.company;
import javax.ws.rs.ApplicationPath;
import javax.ws.rs.core.Application;
@ApplicationPath ( "resources" )
public class ApplicationConfig extends Application {}
Test Class:
package com.company;
import java.util.Date;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
@Path ( "test" )
public class TestApi {
@GET
@Path ( "datetime" )
public String getDate() {
return new Date().toString();
}
}
When I run my web app I expect to be able to receive the current server date/time by calling http://localhost:8080/resources/test/datetime. But I get a 404 error and the message is simply "The requested resource was not found on this server. This error is most commonly caused by a mistyped URL or a broken link". No error in the Eclipse console.
Typically, when Tomcat starts I tend to see each service listed, as it is discovered, on the start output after the 8080 protocol start message:
I am stuck and I need to check on a recent change to another class which is not working on the server.
What can I do to restore this functionality?