I am trying to develop a basic Restful service using Jersey Maven and Eclipse.
I am following the example given here.
I followed the steps as given in the link but when I try to run the project I get a Request Resource Not available
error.
This is my modified dependency in pom.xml file
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-server</artifactId>
<version>1.8</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.4</version>
<scope>provided</scope>
</dependency>
and modified Build in pom.xml
<finalName>maven.secondrest</finalName>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>tomcat-maven-plugin</artifactId>
<version>1.0-beta-1</version>
<configuration>
<port>9999</port>
<path>/</path>
<warFile>${project.basedir}/target/${project.build.finalName}.war</warFile>
</configuration>
</plugin>
</plugins>
The web.xml is very much the same as given in the example:
<display-name>Restful Web Application</display-name>
<servlet>
<servlet-name>jersey-serlvet</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>rest.model</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>jersey-serlvet</servlet-name>
<url-pattern>/rest/*</url-pattern>
</servlet-mapping>
and this is altered java code:
package rest.model;
//imports
@Path("/hello")
public class HelloWorldService {
@GET
@Path("/{param}")
public Response getMsg(@PathParam("param") String msg) {
String output = "Jersey say : " + msg;
return Response.status(200).entity(output).build();
}
}
I am trying to run it by using: mvn tomcat:run
When I enter localhost:9999 it displays a message "Hello World". But when I enter the url as given in the example I get a resource not found error.
This is the url I run: http://localhost:9999/maven.secondrest/rest/hello/nelo