2017-04-19 474 views
2

AppEngine上創建基於Google Tutorial新項目,並切換到Java 1.8, 添加SparkJava依賴關係: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 [email protected]: 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

Google App Engine只有一組可用的Java類。實際列表can be found herejava.util.Optional不在該列表中,因此無法使用。因此,您無法在Google App Engine上使用spark-java。