我想在Android上运行码头新泽西州。
我已经创建了一个实例化一个Servlet的新泽西州一个码头服务器的Android系统。 反正当我开始Jetty和访问REST资源(在我的情况: http://192.168.1.12:8080/api/hello
)我得到一个ContainerException与消息:ResourceConfig实例不包含任何根资源类。 (见下面的异常堆栈跟踪)。
任何想法,为什么?
更多细节:
logcat的是给下面的SEVER警告。
The following errors and warnings have been detected with resource and/or provider classes:
重度:缺少对场相依:私人java.lang.ThreadLocal中com.sun.jersey.server.impl.container.servlet.JSPTemplateProcessor.requestInvoker严重:缺少依赖现场:私人java.lang.ThreadLocal中com.sun.jersey.server .impl.container.servlet.JSPTemplateProcessor.requestInvoker
这是奇怪的原因java.lang.ThreadLocal中适用于安卓和HttpServletRequest和HttpServletResponse的应该是可用,因为我已经包括libs文件夹中的servlet-API-2.5.jar。
新泽西州是依赖于我不得不添加一些使用javax库(JAXB的API-2.2.2.jar,JNDI-1.2.1.jar,STAX-API 1.0-2.jar)项目,并设置--core-库参数暂时忽略有关javax包作为依赖DEX警告。
我还去除(从球衣芯jar包com.sun.jersey.core.impl.provider.entity RenderedImageProvider,DataSourceProvider,MimeMultipartProvider)以下类,以避免对java.awt中和javax.mail依赖性。
异常跟踪:
javax.servlet.UnavailableException: com.sun.jersey.api.container.ContainerException: The ResourceConfig instance does not contain any root resource classes.
at org.eclipse.jetty.servlet.ServletHolder.makeUnavailable(ServletHolder.java:409)
at org.eclipse.jetty.servlet.ServletHolder.initServlet(ServletHolder.java:450)
at org.eclipse.jetty.servlet.ServletHolder.getServlet(ServletHolder.java:331)
at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:511)
at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:476)
at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:119)
at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:517)
at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:226)
at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:935)
at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:404)
at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:184)
at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:870)
at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:117)
at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:116)
at org.eclipse.jetty.server.Server.handle(Server.java:346)
at org.eclipse.jetty.server.HttpConnection.handleRequest(HttpConnection.java:596)
at org.eclipse.jetty.server.HttpConnection$RequestHandler.headerComplete(HttpConnection.java:1051)
at org.eclipse.jetty.http.HttpParser.parseNext(HttpParser.java:592)
at org.eclipse.jetty.http.HttpParser.parseAvailable(HttpParser.java:214)
at org.eclipse.jetty.server.HttpConnection.handle(HttpConnection.java:426)
at org.eclipse.jetty.io.nio.SelectChannelEndPoint.handle(SelectChannelEndPoint.java:520)
at org.eclipse.jetty.io.nio.SelectChannelEndPoint$1.run(SelectChannelEndPoint.java:40)
at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:528)
at java.lang.Thread.run(Thread.java:1019)
启动服务器Android的活动:
public class StartServerActivity extends Activity {
private Server webServer;
private final static String LOG_TAG = "Jetty";
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
System.setProperty("java.net.preferIPv4Stack", "true");
System.setProperty("java.net.preferIPv6Addresses", "false");
webServer = new Server(8080);
ServletHolder servletHolder = new ServletHolder(com.sun.jersey.spi.container.servlet.ServletContainer.class);
servletHolder.setInitParameter("com.sun.jersey.config.property.packages", "com.famenu.server.resources");
ServletContextHandler servletContextHandler = new ServletContextHandler(webServer, "/api", true, false);
servletContextHandler.addServlet(servletHolder, "/hello");
webServer.setHandler(servletContextHandler);
try {
webServer.start();
Log.d(LOG_TAG, "started Web server");
}
catch (Exception e) {
Log.d(LOG_TAG, "unexpected exception starting Web server: " + e);
}
}
}
泽西资源:
package com.famenu.server.resources;
进口javax.ws.rs.GET; 进口javax.ws.rs.Path; 进口javax.ws.rs.Produces;
@Path( “/”)公共类HelloResource {
@GET
@Produces("text/plain")
public String getMsg() {
return "Hello Resource";
}
}
我使用的码头7.3.0.v20110203,新泽西州1.12,Android 1.6的我来到直到此时,另一异常后解释这里