NoClassDefFoundError:使用gradle插件运行Play 2.6时的java.sql.Date

时间:2018-04-10 23:35:20

标签: gradle playframework playframework-2.6

有没有人对play gradle插件好运?我试图运行Play Framework 2.6启动项目。我可以从SBT运行得很好,但是当我从gradle运行时出现以下错误:

play.api.UnexpectedException: Unexpected exception[NoClassDefFoundError: java/sql/Date]
        at play.core.server.DevServerStart$$anon$1.reload(DevServerStart.scala:190)
        at play.core.server.DevServerStart$$anon$1.get(DevServerStart.scala:124)
        at play.core.server.AkkaHttpServer.handleRequest(AkkaHttpServer.scala:202)
        at play.core.server.AkkaHttpServer.$anonfun$createServerBinding$1(AkkaHttpServer.scala:117)
        at akka.stream.impl.fusing.MapAsync$$anon$25.onPush(Ops.scala:1194)
        at akka.stream.impl.fusing.GraphInterpreter.processPush(GraphInterpreter.scala:519)
        at akka.stream.impl.fusing.GraphInterpreter.processEvent(GraphInterpreter.scala:482)
        at akka.stream.impl.fusing.GraphInterpreter.execute(GraphInterpreter.scala:378)
        at akka.stream.impl.fusing.GraphInterpreterShell.runBatch(ActorGraphInterpreter.scala:

我正在使用带有以下build.gradle的Java 1.8:

plugins {
    id 'play'
    id 'idea'
}

def playVersion = "2.6.13"
def scalaVersion = System.getProperty("scala.binary.version", /* default = */ "2.12")

model {
    components {
        play {
            platform play: playVersion, scala: scalaVersion, java: '1.8'
            injectedRoutesGenerator = true

            sources {
                twirlTemplates {
                    defaultImports = TwirlImports.JAVA
                }   
            }   
        }   
    }   
}

dependencies {
    play "com.typesafe.play:play-guice_$scalaVersion:$playVersion"
    play "com.typesafe.play:play-logback_$scalaVersion:$playVersion"
    play "com.h2database:h2:1.4.196"

    playTest "org.assertj:assertj-core:3.6.2"
    playTest "org.awaitility:awaitility:2.0.0"
}

repositories {
    jcenter()
    maven {
        name "lightbend-maven-releases"
        url "https://repo.lightbend.com/lightbend/maven-release"
    }   
    ivy {
        name "lightbend-ivy-release"
        url "https://repo.lightbend.com/lightbend/ivy-releases"
        layout "ivy"
    }   
}

2 个答案:

答案 0 :(得分:1)

您需要将java_home设置为使用Java 1.8版本。显然,play gradle插件需要一个Java home。

http://foo.com/controller1

app.UseMvc(routes => routes.MapRoute("default", "IRate/{controller}/{action}/{id?}"));

答案 1 :(得分:0)

我发现了这个问题,我的$ JAVA_HOME设置为我的Java 9路径,但java / javac设置为Java 8.这导致我的gradle使用了错误的java版本。修复我的$ JAVA_HOME后,它可以正常工作。

如果有其他人遇到这个问题我会留下这个。