【发布时间】:2011-11-17 07:20:35
【问题描述】:
我想使用带有 JAX-RS(resteasy 或 jersey)的嵌入式码头制作 RESTful 服务。
我正在尝试使用 maven/eclipse 设置进行创建。
如果我尝试关注http://wikis.sun.com/pages/viewpage.action?pageId=21725365 链接,我将无法解决来自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();
}
}
即使这样也行不通。 谁能给我一些建议/教程/示例?
【问题讨论】: