Reputation: 11572
Okay, I literally don't know how much simpler I can make this test case. I have the most minimal code in all respects, and yet it works in Jersey 1.x and fails with the Glassfish version. Can anyone shed some light on what I'm doing wrong?
By "failing" and "not working", I mean that, when I stand it up in a Tomcat container and try to hit it in a browser, the first version is successful, but the second one fails.
@Path("/service")
public class MyService {
@GET
@Path("/test")
public String test() {
return "Yay!";
}
}
... working web.xml with Jersey 1.x ...
<servlet>
<servlet-name>jersey-servlet</servlet-name>
<servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>com.sun.jersey.config.property.packages</param-name>
<param-value>my.service.package</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>jersey-servlet</servlet-name>
<url-pattern>/rest/*</url-pattern>
</servlet-mapping>
... just replace two strings for Glassfish, and the whole thing breaks.
<servlet>
<servlet-name>jersey-servlet</servlet-name>
<servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>jersey.config.server.provider.packages</param-name>
<param-value>my.service.package</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>jersey-servlet</servlet-name>
<url-pattern>/rest/*</url-pattern>
</servlet-mapping>
pom.xml for Jersey 1.x
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-server</artifactId>
<version>1.18.3</version>
</dependency>
... and for 2.x ...
<dependency>
<groupId>org.glassfish.jersey.core</groupId>
<artifactId>jersey-server</artifactId>
<version>2.14</version>
</dependency>
Upvotes: 1
Views: 1809
Reputation: 208964
Using the below dependency should pull in all the required dependencies you need to get up and running.
<dependency>
<groupId>org.glassfish.jersey.containers</groupId>
<artifactId>jersey-container-servlet</artifactId>
<version>2.14</version>
</dependency>
Upvotes: 1