我希望泽西岛可以轻松部署到谷歌应用引擎,因为它应该得到支持(http://code.google.com/p/googleappengine/wiki/WillItPlayInJava),有几个人提到他们让它工作(http://tugdualgrall.blogspot.ca/2010/02/create-and-deploy-jax-rs-rest-service.html) 但它不起作用......
我已添加到我的web.xml:
<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>sample.hello.resources</param-value>
</init-param>
<init-param>
<param-name>com.sun.jersey.config.feature.DisableWADL</param-name>
<param-value>true</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
我添加到了类路径:jersey-bundle-1.14.jar(我甚至尝试过只使用核心,servlet和服务器而我甚至只尝试过1.5)
但我仍然坚持这个:
WARNING: failed Jersey REST Service: java.lang.IncompatibleClassChangeError: Implementing class
Oct 27, 2012 6:17:06 PM com.google.apphosting.utils.jetty.JettyLogger warn
WARNING: failed com.google.appengine.tools.development.DevAppEngineWebAppContext@68c12474{/,/Users/anthony/workspaces/gae/restfulapp/war}: java.lang.IncompatibleClassChangeError: Implementing class
Oct 27, 2012 6:17:06 PM com.google.apphosting.utils.jetty.JettyLogger warn
WARNING: failed JettyContainerService$ApiProxyHandler@365878d2: java.lang.IncompatibleClassChangeError: Implementing class
Oct 27, 2012 6:17:06 PM com.google.apphosting.utils.jetty.JettyLogger warn
WARNING: Error starting handlers
java.lang.IncompatibleClassChangeError: Implementing class
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClassCond(ClassLoader.java:631)
at java.lang.ClassLoader.defineClass(ClassLoader.java:615)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:141)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:283)
at java.net.URLClassLoader.access$000(URLClassLoader.java:58)
at java.net.URLClassLoader$1.run(URLClassLoader.java:197)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at com.google.appengine.tools.development.IsolatedAppClassLoader.loadClass(IsolatedAppClassLoader.java:207)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
at com.sun.jersey.api.core.ScanningResourceConfig.init(ScanningResourceConfig.java:79)
at com.sun.jersey.api.core.PackagesResourceConfig.init(PackagesResourceConfig.java:104)
at com.sun.jersey.api.core.PackagesResourceConfig.<init>(PackagesResourceConfig.java:78)
at com.sun.jersey.api.core.PackagesResourceConfig.<init>(PackagesResourceConfig.java:89)
at com.sun.jersey.spi.container.servlet.WebComponent.createResourceConfig(WebComponent.java:696)
at com.sun.jersey.spi.container.servlet.WebComponent.createResourceConfig(WebComponent.java:674)
at com.sun.jersey.spi.container.servlet.WebComponent.init(WebComponent.java:206)
at com.sun.jersey.spi.container.servlet.ServletContainer.init(ServletContainer.java:373)
at com.sun.jersey.spi.container.servlet.ServletContainer.init(ServletContainer.java:556)
at javax.servlet.GenericServlet.init(GenericServlet.java:212)
at org.mortbay.jetty.servlet.ServletHolder.initServlet(ServletHolder.java:440)
at org.mortbay.jetty.servlet.ServletHolder.doStart(ServletHolder.java:263)
at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:50)
at org.mortbay.jetty.servlet.ServletHandler.initialize(ServletHandler.java:685)
at org.mortbay.jetty.servlet.Context.startContext(Context.java:140)
at org.mortbay.jetty.webapp.WebAppContext.startContext(WebAppContext.java:1250)
at org.mortbay.jetty.handler.ContextHandler.doStart(ContextHandler.java:517)
at org.mortbay.jetty.webapp.WebAppContext.doStart(WebAppContext.java:467)
at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:50)
at org.mortbay.jetty.handler.HandlerWrapper.doStart(HandlerWrapper.java:130)
at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:50)
at org.mortbay.jetty.handler.HandlerWrapper.doStart(HandlerWrapper.java:130)
at org.mortbay.jetty.Server.doStart(Server.java:224)
at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:50)
at com.google.appengine.tools.development.JettyContainerService.startContainer(JettyContainerService.java:205)
at com.google.appengine.tools.development.AbstractContainerService.startup(AbstractContainerService.java:249)
at com.google.appengine.tools.development.DevAppServerImpl.start(DevAppServerImpl.java:157)
at com.google.appengine.tools.development.DevAppServerMain$StartAction.apply(DevAppServerMain.java:333)
at com.google.appengine.tools.util.Parser$ParseResult.applyArgs(Parser.java:48)
at com.google.appengine.tools.development.DevAppServerMain.<init>(DevAppServerMain.java:269)
at com.google.appengine.tools.development.DevAppServerMain.main(DevAppServerMain.java:245)
我错过了什么?我应该为gae使用另一个jax-rs实现吗? 谢谢你的回答!
答案 0 :(得分:9)
好吧,我发现:显然(看看我在问题中发布的堆栈跟踪),GAE不允许Jersey使用其类加载器来扫描可用的休息资源。 所以,我详细阅读了Jersey文档the Jersey documentation regarding the deployments,我发现我可以手动指定休息资源到泽西岛。
这是web.xml:
<servlet-mapping>
<servlet-name>Jersey Web Application</servlet-name>
<url-pattern>/rest/*</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>Jersey Web Application</servlet-name>
<servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer
</servlet-class>
<init-param>
<param-name>javax.ws.rs.Application</param-name>
<param-value>sample.hello.bean.MyApplication</param-value>
</init-param>
</servlet>
您可以注意到我现在有一个Application类:
package sample.hello.bean;
import java.util.HashSet;
import java.util.Set;
import javax.ws.rs.core.Application;
import sample.hello.resources.HelloResource;
public class MyApplication extends Application {
public Set<Class<?>> getClasses() {
Set<Class<?>> s = new HashSet<Class<?>>();
s.add(HelloResource.class);
return s;
}
}
只需手动指定您的剩余资源,将它们添加到集合中。 适用于jersey-bundle-1.14.jar
答案 1 :(得分:0)
谢谢这对我也很有帮助。但jersey documentation也表示我们可以使用包进行配置。 我们没有任何其他选择在包中声明。因为对于每个新资源,我们都需要修改MyApplication类
答案 2 :(得分:0)
<!-- Add following dependency in pom.xml -->
<dependency>
<groupId>cglib</groupId>
<artifactId>cglib</artifactId>
<version>2.2.2</version>
</dependency>