So I started to read this tutorial about how to develop a Restful service with Jersey. I want to develop Rest service that sends the data from a MySQL database to an Android client. I read and followed the steps on the tutorial and made my own resource classes, but when I tried to run the service on Apache I got the following error here.
I’m just starting to experiment with web services and Rest, I have read the information related to the subject from that IBM site and I thought I got the hang of it, but I’m really lost as to why is not working.
My web.xml is as follows
<?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>TesterRest</display-name>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
</welcome-file-list>
<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.mx.ipn.escom.testerRest.resources</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Jersey REST Service</servlet-name>
<url-pattern>/rest/*</url-pattern>
</servlet-mapping>
</web-app>
This is my resource class:
package com.mx.ipn.escom.testerRest.resources;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Request;
import javax.ws.rs.core.UriInfo;
import javax.xml.bind.annotation.XmlRootElement;
import com.mx.ipn.escom.testerRest.dao.TemaDao;
import com.mx.ipn.escom.testerRest.db.Connector;
import com.mx.ipn.escom.testerRest.modelo.Tema;
@XmlRootElement
@Path("/temas")
public class TemaResource {
@Context
UriInfo uriInfo;
@Context
Request request;
@GET
@Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
public List<Tema> getTemas() throws SQLException{
TemaDao temaDao = new TemaDao();
List<Tema> temas=temaDao.getTemas();
temaDao.terminarSesion();
return temas;
}
}
My class for database connection works fine, so that one isn’t the problem.
I’m using Eclipse 3.6 to develop and Apache Tomcat 6.
I’m completely new to JAXB, so if anyone can give me guidelines to what kind of annotations am I missing I would appreciate it.
Based on your screenshot I think you should update your web.xml to have the correct package name:
The
mxis missing from your configuration.