0

I can start up my app via a main method using an embedded Grizzly container, and all my Jersey resources respond as I expect. But when I drop my war in the webapps directory ($CATALINA_HOME/webapps/ROOT.war), I get 404s for everything. What might be causing this?

My 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"
         xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
         xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
         id="WebApp_ID" version="2.5">
  <display-name>example</display-name>
  <servlet>
    <servlet-name>jersey</servlet-name>
    <servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
    <init-param>
      <param-name>com.sun.jersey.config.property.packages</param-name>
      <param-value>com.example</param-value>
    </init-param>

    <load-on-startup>1</load-on-startup>
  </servlet>
  <servlet-mapping>
    <servlet-name>jersey</servlet-name>
    <url-pattern>/*</url-pattern>
  </servlet-mapping>
</web-app>

Edit: One resource is exposed at /hello. I've tried changing the <url-pattern> to /hello, /rest/*, rest/*, and just *, and trying various curl statements like:

$ curl -i http://localhost:8080/rest/hello
HTTP/1.1 404 Not Found
Server: Apache-Coyote/1.1
Content-Length: 0
Date: Tue, 21 Mar 2017 06:07:10 GMT

Hello resource:

package com.example.hello;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;

@Path("hello")
public class HelloWorldResource {

  @GET
  @Produces(MediaType.TEXT_PLAIN)
  public String sayhello() {
    return "hello";
  }
}
Travis Well
  • 947
  • 10
  • 32
  • use something else in place of /* and then check – gladiator Mar 21 '17 at 05:39
  • @gladiator like what? One resource is accessible at /hello, but putting /hello in did not expose that resource. It's still a 404. – Travis Well Mar 21 '17 at 05:48
  • here in url pattern set something like rest/* and then all rest services will be accessed with something like rest/SERVICENAME* – gladiator Mar 21 '17 at 06:03
  • @gladiator I just tried this and the behavior is still the same. https://da.gd/yO6UI – Travis Well Mar 21 '17 at 06:11
  • can you add your rest service class here – gladiator Mar 21 '17 at 06:43
  • @gladiator I actually can't find that class com.sun.jersey.spi.container.servlet.ServletContainer. Maybe it's a Jersey 1.x class and I'm trying to use 2.x. I don't know what the 2.x equivalent is. Could this be the issue? Surprised there was no ClassNotFoundException though. – Travis Well Mar 21 '17 at 07:13
  • add @Path("sayhello") above sayhello method and in url pattern /rest/* and then access http://localhost:8080/rest/hello/sayhello – gladiator Mar 21 '17 at 07:34

0 Answers0