1

我正在努力在 Eclipse Juno 中配置 JAX-RS 以部署到 Google App Engine,事实上,我还没有让本地部署工作(Jetty)。

这是我遇到的堆栈跟踪,但我不明白为什么当我包含所有球衣 jar 文件时它仍然无法找到类 com.sun.jersey.spi.container.servlet.ServletContainer(过度杀伤我知道)和所有 JAXB JAR 文件(我什至还没那么关心!)。

2012-11-25 22:22:50.622 java[5703:707] [Java CocoaComponent compatibility mode]: Enabled
2012-11-25 22:22:50.623 java[5703:707] [Java CocoaComponent compatibility mode]: Setting timeout for SWT to 0.100000
Nov 25, 2012 10:22:51 PM com.google.apphosting.utils.jetty.JettyLogger info
INFO: Logging to JettyLogger(null) via com.google.apphosting.utils.jetty.JettyLogger
Nov 25, 2012 10:22:51 PM com.google.apphosting.utils.config.AppEngineWebXmlReader readAppEngineWebXml
INFO: Successfully processed /Users/Rob/Development/HillingarIncidentReporting/HillingarGaeServer/war/WEB-INF/appengine-web.xml
Nov 25, 2012 10:22:51 PM com.google.apphosting.utils.config.AbstractConfigXmlReader readConfigXml
INFO: Successfully processed /Users/Rob/Development/HillingarIncidentReporting/HillingarGaeServer/war/WEB-INF/web.xml
Nov 25, 2012 10:22:52 PM com.google.apphosting.utils.jetty.JettyLogger warn
WARNING: EXCEPTION 
java.lang.ClassNotFoundException: com.sun.jersey.spi.container.servlet.ServletContainer
    at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
    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 org.mortbay.util.Loader.loadClass(Loader.java:91)
    at org.mortbay.util.Loader.loadClass(Loader.java:71)
    at org.mortbay.jetty.servlet.Holder.doStart(Holder.java:73)
    at org.mortbay.jetty.servlet.ServletHolder.doStart(ServletHolder.java:242)
    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)
Nov 25, 2012 10:22:52 PM com.google.appengine.tools.development.ApiProxyLocalImpl log
SEVERE: javax.servlet.ServletContext log: unavailable
javax.servlet.UnavailableException: com.sun.jersey.spi.container.servlet.ServletContainer
    at org.mortbay.jetty.servlet.Holder.doStart(Holder.java:79)
    at org.mortbay.jetty.servlet.ServletHolder.doStart(ServletHolder.java:242)
    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)

Nov 25, 2012 10:22:52 PM com.google.apphosting.utils.jetty.JettyLogger warn
WARNING: failed Jersey Web Application: java.lang.NullPointerException
Nov 25, 2012 10:22:52 PM com.google.apphosting.utils.jetty.JettyLogger warn
WARNING: Failed startup of context com.google.appengine.tools.development.DevAppEngineWebAppContext@798baf36{/,/Users/Rob/Development/HillingarIncidentReporting/HillingarGaeServer/war}
java.lang.NullPointerException
    at java.lang.Class.isAssignableFrom(Native Method)
    at org.mortbay.jetty.servlet.ServletHolder.doStart(ServletHolder.java:256)
    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)
Nov 25, 2012 10:22:52 PM com.google.appengine.tools.development.DevAppServerImpl start
INFO: The server is running at http://localhost:8888/
Nov 25, 2012 10:22:52 PM com.google.appengine.tools.development.DevAppServerImpl start
INFO: The admin console is running at http://localhost:8888/_ah/admin
2012-11-25 22:22:55.378 java[5703:6c03] Unable to obtain JNIEnv for context: 0x0

这是 Eclipse 项目中指定的所有 JAR 文件的屏幕截图 - 我假设 Jetty 将其用于本地部署?

构建路径中引用的 JAR - 配置构建路径

此外,这是 /war/WEB-INF/lib 文件夹中的 SAME Jersey 和 JAXB jar 文件的副本,正如许多其他论坛所建议的那样,它最终部署在 Google App Engine 中时

部署的战争库文件

问题 1 首先,我需要解决 JAR 未加载的原因。我试图更改它们的加载顺序(我似乎只能在构建路径 - 配置构建路径中这样做),所以在这里我首先设置 jersey-servlet-1.15.jar 文件(因为它有违规类当下)。

每次尝试解决此问题后,我都会清理我的项目。有谁知道我可能会错过什么?

问题 2 此外,在较低优先级上,我还想知道 Jersey 和 JAXB 罐子实际上需要什么,我怀疑我只需要一个非常小的子集。也许所有的罐子都是冲突的,虽然我试过只有 jersey-servley-1.15.jar 并且它仍然抱怨!

问题 3 我注意到 Jersey 包含 asm-3.1.jar - 但 GAE 已经包含 asm-4.0.jar,我是否应该不包含 3.1,因为新版本已经存在?

问题 4 当我尝试创建一个扩展 ServletContextListener 的类时,Eclipse 没有在类列表中提供“ServletContextListener”,但在类路径中我可以清楚地看到“App Engine SDK”版本 1.7.3 包含 servlet-api。 jar,我怀疑它在运行时默认也包含在 Jetty 中。

请,您的帮助将不胜感激。

4

1 回答 1

1

也许您需要在 web.xml 中添加 servlet 映射?例如(使用 Spring,但应该类似):

<servlet>
    <servlet-name>REST Service</servlet-name>
    <servlet-class>com.sun.jersey.spi.spring.container.servlet.SpringServlet</servlet-class>
    <init-param>
        <param-name>com.sun.jersey.config.property.packages</param-name>
        <param-value>com.evogro</param-value>
    </init-param>
    <init-param>
        <param-name>com.sun.jersey.spi.container.ContainerRequestFilters</param-name>
        <param-value>com.sun.jersey.api.container.filter.LoggingFilter</param-value>
    </init-param>
    <init-param>
        <param-name>com.sun.jersey.spi.container.ContainerResponseFilters</param-name>
        <param-value>com.sun.jersey.api.container.filter.LoggingFilter</param-value>
    </init-param>
        <load-on-startup>1</load-on-startup>
</servlet>

<servlet-mapping>
    <servlet-name>REST Service</servlet-name>
    <url-pattern>/api/*</url-pattern>
</servlet-mapping>

Q2:您的列表与我的匹配(通过 maven 包含)。我正在使用球衣 1.13。我不知道这是否是您可以逃脱的最低限度

Q3:我已将 ASM-3.3.1 作为 datanucleus-enhancer 的依赖项包含在内。它在要部署的 jar 列表中。GAE 将换掉它不喜欢的任何罐子

Q4:ServletContextListener 是一个接口,你自己实现。在新类向导中,Eclipse 应该在添加接口部分向您提供它。

我希望其中一些可以解决您的一些问题。我对这些东西很陌生!

于 2012-11-29T13:16:37.513 回答