com.google.api.server.spi.SystemServiceServlet ClassNotFoundException 运行 App Engine 项目

com.google.api.server.spi.SystemServiceServlet ClassNotFoundException running App Engine Project

我有一个 android 应用程序,我想添加一个服务器后端以与 GCM 通信。我遵循了本教程:https://github.com/GoogleCloudPlatform/gradle-appengine-templates/tree/master/GcmEndpoints 并在 android 工作室的 android 项目中创建了一个带有 Google 云消息模块的 App Engine 后端。但是,当我 运行 App Engine 后端项目时,出现此错误:

java.lang.ClassNotFoundException: com.google.api.server.spi.SystemServiceServlet.

全栈如下:

at java.net.URLClassLoader.run(URLClassLoader.java:366)
at java.net.URLClassLoader.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
at com.google.appengine.tools.development.IsolatedAppClassLoader.loadClass(IsolatedAppClassLoader.java:216)
at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
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:254)
at com.google.appengine.tools.development.AbstractContainerService.startup(AbstractContainerService.java:305)
at com.google.appengine.tools.development.AutomaticInstanceHolder.startUp(AutomaticInstanceHolder.java:26)
at com.google.appengine.tools.development.AbstractModule.startup(AbstractModule.java:79)
at com.google.appengine.tools.development.Modules.startup(Modules.java:97)
at com.google.appengine.tools.development.DevAppServerImpl.doStart(DevAppServerImpl.java:255)
at com.google.appengine.tools.development.DevAppServerImpl.access[=13=]0(DevAppServerImpl.java:47)
at com.google.appengine.tools.development.DevAppServerImpl.run(DevAppServerImpl.java:213)
at com.google.appengine.tools.development.DevAppServerImpl.run(DevAppServerImpl.java:211)
at java.security.AccessController.doPrivileged(Native Method)
at com.google.appengine.tools.development.DevAppServerImpl.start(DevAppServerImpl.java:211)
at com.google.appengine.tools.development.DevAppServerMain$StartAction.apply(DevAppServerMain.java:277)
at com.google.appengine.tools.util.Parser$ParseResult.applyArgs(Parser.java:48)
at com.google.appengine.tools.development.DevAppServerMain.run(DevAppServerMain.java:219)
at com.google.appengine.tools.development.DevAppServerMain.main(DevAppServerMain.java:210)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:134)

web.xml 文件的内容如下:

<?xml version="1.0" encoding="utf-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee" version="2.5">
<servlet>
    <servlet-name>SystemServiceServlet</servlet-name>
    <servlet-class>com.google.api.server.spi.SystemServiceServlet</servlet-class>
    <init-param>
        <param-name>services</param-name>
        <param-value>com.example.mymodule.backend.RegistrationEndpoint, com.example.mymodule.backend.MessagingEndpoint</param-value>
    </init-param>

<welcome-file-list>
    <welcome-file>index.html</welcome-file>
</welcome-file-list>
</web-app>

这是传递给 Java 引擎的命令行。

"C:\Program Files\Java\jdk1.7.0_80\bin\java" -javaagent:C:\Users\xx\.gradle\appengine-sdk\appengine-java-sdk-1.9.4\lib\agent\appengine-agent.jar -Xbootclasspath/p:C:\Users\xx\.gradle\appengine-sdk\appengine-java-sdk-1.9.4\lib\override\appengine-dev-jdk-overrides.jar -Didea.launcher.port=7532 "-Didea.launcher.bin.path=C:\Program Files (x86)\Android\android-studio\bin" -Dfile.encoding=windows-1252 -classpath "C:\Users\xx\.gradle\appengine-sdk\appengine-java-sdk-1.9.4\lib\appengine-tools-api.jar;C:\Program Files (x86)\Android\android-studio\lib\idea_rt.jar" com.intellij.rt.execution.application.AppMain com.google.appengine.tools.development.DevAppServerMain --address=127.0.0.1 --port=8080 C:\Users\xx\Documents\Android\GroceryList\backend\src\main\webapp

非常感谢任何关于如何修复此错误的建议。

我通过将 App Engine 项目的 "War Path" 设置为 \build\exploded-app 解决了这个问题。这应该由 Android Studio 自动生成。出于某种原因,当我添加新的应用引擎模块时,没有生成新的配置,所以我必须手动创建应用引擎的配置和设置。