3.) Note the value of com.sun.jersey.config.property.packages, this tells us that it will examine the classes inside com.ipiel.xxx for REST enabled web services.
<servlet>
<servlet-name>Jersey REST Service</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>com.ipiel.xxx</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Jersey REST Service</servlet-name>
<url-pattern>/api/*</url-pattern>
</servlet-mapping>
4.) Make sure that you have the ff definition in your pom.xml
@Path("/hello")
public class Hello {
@GET
@Path("/world")
public Response sayHello() {
String hello = "Hello World!";
return Response.status(200).entity(hello).build();
}
}
5.) Compile and deploy the war/ear in a container (jboss, glassfish, etc). 6.) Now you can access the web app in your localhost: http://localhost:port/appname/api/hello/world And it should output "Hello World!". Note: In case you want to add parameter to your web service, this is how you will code it:
<dependency>
<groupId>com.sun.jersey.contribs</groupId>
<artifactId>jersey-spring</artifactId>
<version>${jersey.version}</version>
<exclusions>
<exclusion>
<groupId>org.springframework</groupId>
<artifactId>spring-aop</artifactId>
</exclusion>
<exclusion>
<groupId>org.springframework</groupId>
<artifactId>spring</artifactId>
</exclusion>
<exclusion>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
</exclusion>
<exclusion>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
</exclusion>
<exclusion>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId>
</exclusion>
<exclusion>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
</exclusion>
</exclusions>
</dependency>
@Path("/reverse")
@POST
@Consumes("application/x-www-form-urlencoded")
@Produces({ MediaType.APPLICATION_JSON })
public Response reverse(@FormParam("orderId") long orderId) {
}