1
votes

i've already tried a lot suggestions, but none seemed to work for me. When deploying my jersey application on tomcat, no errors occur. But when accessing any of the specified paths it gives me 404 aka resource is not available. I'll give you relevant parts of my files:

web.xml

<web-app>
<servlet>
  <servlet-name>o2r</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.mypackage.project.MyClass</param-value>
  </init-param>
  <load-on-startup>1</load-on-startup>
</servlet>

<servlet-mapping>
  <servlet-name>o2r</servlet-name>
  <url-pattern>/*</url-pattern>
</servlet-mapping>

<session-config>
  <session-timeout>30</session-timeout>
</session-config>
</web-app>

MyClass.java

package com.mypackage.project;
... //imports etc
@Path("control")
public class MyClass
{
    @GET
    @Path("{param}")
    public Response getMsg(@PathParam("param") String msg) 
    //this part is from some mykong tutorial
    {
    String output = "Jersey say : " + msg;
    return Response.status(200).entity(output).build();
    }
}

pom.xml

...
<dependency>
    <groupId>org.glassfish.jersey.containers</groupId>
    <artifactId>jersey-container-servlet</artifactId>
    <version>2.7</version>
    <scope>provided</scope>
</dependency>
<dependency>
    <groupId>org.apache.tomcat</groupId>
    <artifactId>tomcat-catalina</artifactId>
    <version>7.0.16</version>
</dependency>
...

When trying to access

http://localhost:8080/MyClass/control/lala 

(which should return "Jersey say : lala") it just gives me 404. Note: MyClass is the correct name of my .WAR-file.

1
jersey.config.server.provider.packages - com.mypackage.project.MyClass or just com.mypackage.project?Leos Literak
Unrelated to this issue but still wrong: you are missing a provided scope on that tomcat dependency there, that can lead to dependencies ending up on the compile scope that you don't want to deploy with your application at all. And its the wrong version too.Gimby

1 Answers

1
votes

try this

com.mypackage.project instead of com.mypackage.project.MyClass