2

我希望 Jersey 能够轻松部署到 Google App Engine,因为它应该是受支持的 ( http://code.google.com/p/googleappengine/wiki/WillItPlayInJava ) 并且有几个人提到他们让它工作了 ( http:// tugdualgrall.blogspot.ca/2010/02/create-and-deploy-jax-rs-rest-service.html)但它不起作用......

  • 我使用 Eclipse 的 gae 插件创建了一个新项目(使用 gae sdk 1.7.3)
  • 我添加到我的 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 实现吗?感谢您的回答!

4

3 回答 3

9

好的,我发现:显然(查看我在问题中发布的堆栈跟踪),GAE 不允许 Jersey 使用其类加载器来扫描可用的剩余资源。因此,我详细阅读了Jersey 文档以及有关部署的 Jersey 文档,我发现我可以手动将 Rest 资源指定给 Jersey。

这是 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

于 2012-10-27T19:47:32.163 回答
0

谢谢 这也帮助了我。但是球衣文档也说我们可以使用包进行配置。难道我们没有任何其他选项可以在包中声明。因为对于每个新资源,我们都需要修改 MyApplication 类

于 2013-01-22T15:51:38.367 回答
0
<!-- Add following dependency in pom.xml -->
<dependency>
            <groupId>cglib</groupId>
            <artifactId>cglib</artifactId>
            <version>2.2.2</version>
</dependency>
于 2017-07-25T11:54:19.287 回答