I want make RESTful services using embedded jetty with JAX-RS (either resteasy or jersey).
I am trying to create with maven/eclipse setup.
if I try to follow http://wikis.sun.com/pages/viewpage.action?pageId=21725365 link I am not able to resolve error from ServletHolder sh = new ServletHolder(ServletContainer.class);
public class Main {
@Path("/")
public static class TestResource {
@GET
public String get() {
return "GET";
}
}
/**
* @param args the command line arguments
*/
public static void main(String[] args) throws Exception {
ServletHolder sh = new ServletHolder(ServletContainer.class);
/*
* For 0.8 and later the "com.sun.ws.rest" namespace has been renamed to
* "com.sun.jersey". For 0.7 or early use the commented out code instead
*/
// sh.setInitParameter("com.sun.ws.rest.config.property.resourceConfigClass",
// "com.sun.ws.rest.api.core.PackagesResourceConfig");
// sh.setInitParameter("com.sun.ws.rest.config.property.packages",
// "jetty");
sh.setInitParameter("com.sun.jersey.config.property.resourceConfigClass",
"com.sun.jersey.api.core.PackagesResourceConfig");
sh.setInitParameter("com.sun.jersey.config.property.packages",
"edu.mit.senseable.livesingapore.platform.restws");
// sh.setInitParameter("com.sun.jersey.config.property.packages",
// "jetty");
Server server = new Server(9999);
ServletContextHandler context = new ServletContextHandler(server, "/",
ServletContextHandler.SESSIONS);
context.addServlet(sh, "/*");
server.start();
server.join();
// Client c = Client.create();
// WebResource r = c.resource("http://localhost:9999/");
// System.out.println(r.get(String.class));
//
// server.stop();
}
}
even this is not working. can anyone suggest me something/tutorial/example ?