我基于Google Tutorial创建新项目并切换到Java 1.8, 添加SparkJava依赖项:
dependencies {
compile 'com.google.appengine:appengine:+'
compile 'com.sparkjava:spark-core:2.5.5'
compile 'com.google.cloud:google-cloud-datastore:0.13.0-beta'
}
并根据SparkJava文档创建web.xml配置:
<web-app xmlns="http://java.sun.com/xml/ns/javaee" version="2.5">
<filter>
<filter-name>SparkFilter</filter-name>
<filter-class>spark.servlet.SparkFilter</filter-class>
<init-param>
<param-name>applicationClass</param-name>
<param-value>me.drozdzynski.test.App</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>SparkFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
</web-app>
编译并启动本地Google Development Server之后,我有错误:
WARNING: failed JettyContainerService$ApiProxyHandler@14028087: java.lang.NoClassDefFoundError: java.util.Optional is a restricted class. Please see the Google App Engine developer's guide for more details.
Apr 19, 2017 7:22:01 AM com.google.apphosting.utils.jetty.JettyLogger warn
WARNING: Error starting handlers
java.lang.NoClassDefFoundError: java.util.Optional is a restricted class. Please see the Google App Engine developer's guide for more details.
at com.google.appengine.tools.development.agent.runtime.Runtime.reject(Runtime.java:50)
at spark.Service.<init>(Service.java:74)
at spark.Service.ignite(Service.java:99)
at spark.Spark$SingletonHolder.<clinit>(Spark.java:49)
at spark.Spark.getInstance(Spark.java:53)
at spark.Spark.<clinit>(Spark.java:59)
at me.drozdzynski.test.App.init(App.java:11)
at spark.servlet.SparkFilter.init(SparkFilter.java:69)
at org.mortbay.jetty.servlet.FilterHolder.doStart(FilterHolder.java:97)
at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:50)
at org.mortbay.jetty.servlet.ServletHandler.initialize(ServletHandler.java:662)
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:268)
at com.google.appengine.tools.development.AbstractContainerService.startup(AbstractContainerService.java:284)
at com.google.appengine.tools.development.AutomaticInstanceHolder.startUp(AutomaticInstanceHolder.java:26)
at com.google.appengine.tools.development.AbstractModule.startup(AbstractModule.java:87)
at com.google.appengine.tools.development.Modules.startup(Modules.java:105)
at com.google.appengine.tools.development.DevAppServerImpl.doStart(DevAppServerImpl.java:262)
at com.google.appengine.tools.development.DevAppServerImpl.access$000(DevAppServerImpl.java:45)
at com.google.appengine.tools.development.DevAppServerImpl$1.run(DevAppServerImpl.java:217)
at com.google.appengine.tools.development.DevAppServerImpl$1.run(DevAppServerImpl.java:215)
at java.security.AccessController.doPrivileged(Native Method)
at com.google.appengine.tools.development.DevAppServerImpl.start(DevAppServerImpl.java:215)
at com.google.appengine.tools.development.DevAppServerMain$StartAction.apply(DevAppServerMain.java:349)
at com.google.appengine.tools.util.Parser$ParseResult.applyArgs(Parser.java:47)
at com.google.appengine.tools.development.DevAppServerMain.run(DevAppServerMain.java:222)
at com.google.appengine.tools.development.DevAppServerMain.main(DevAppServerMain.java:213)
答案 0 :(得分:0)
Google App Engine只有一组可用的Java类。实际列表can be found here。 java.util.Optional
不在该列表中,因此无法使用。因此,您无法在Google App Engine上使用spark-java。
答案 1 :(得分:0)
java8现在可以在GAE上使用,现在支持所有公共JDK API
https://cloud.google.com/appengine/docs/standard/java/runtime-java8