Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting 404 error with TOMCAT-Jersey Rest

I am using JERSEY2.15:-

java class:-

package packages.newJersey;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;

@Path("/rest")
public class SimpleWebService {

    private static String versions = "4.1";

    @GET
    @Produces(MediaType.TEXT_HTML)
    public String simpleMessage() {

        return "<p>This is a simple REST</p>";

    }

    @Path("/version")
    @GET
    @Produces(MediaType.TEXT_HTML)
    public String version() {

        return "<p>Version Number:</p> " + versions;

    }
}

web.xml:-

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns="http://java.sun.com/xml/ns/javaee"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
    id="WebApp_ID" version="3.0">
    <display-name>LatestJersey</display-name>
    <servlet>
        <servlet-name>Jersey REST Service</servlet-name>
        <servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
        <init-param>
            <param-name>jersey.config.server.provider.package</param-name>
            <param-value>packages.newJersey</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>Jersey REST Service</servlet-name>
        <url-pattern>/hello/*</url-pattern>
    </servlet-mapping>
</web-app>

even though i use display name as :- LatestJersey

by default tomcat is opening:- http://localhost:8080/RESTFULServiceWithLatestJersey/

and when i hit:- http://localhost:8080/RESTFULServiceWithLatestJersey/hello/rest

I AM GETTING 404 ERROR

Could someone please help me here?

like image 706
Naga Sarath Chand Avatar asked Oct 31 '22 10:10

Naga Sarath Chand


1 Answers

Everything looks good, except for this

jersey.config.server.provider.package

It should be

jersey.config.server.provider.packages  

You're missing the s

like image 128
Paul Samsotha Avatar answered Nov 15 '22 05:11

Paul Samsotha