java.lang.ClassNotFoundException:play.core.server.DevServerStart

时间:2018-07-14 14:45:47

标签: playframework sbt

我正在尝试创建一个项目,该项目包含2个子项目(两个播放应用程序),这些子项目依赖于一个公共库,但是我在运行两个播放应用程序时遇到了麻烦。

这是我的build.sbt:

lazy val playDeps = Seq(
  ws,
  filters,
  evolutions,
  guice,
  "org.scalatestplus.play"  %%  "scalatestplus-play"  % "3.1.1" % Test
)

lazy val slickDeps = Seq(
  "com.typesafe.play" %%  "play-slick"            % "3.0.1",
  "com.typesafe.play" %%  "play-slick-evolutions" % "3.0.1",
  "org.postgresql"    %   "postgresql"            % "42.1.4"
)

lazy val commonDeps = Seq(
  "org.scalatest" %%  "scalatest" % "3.0.4" % Test
)

lazy val commonSettings = Seq(
  organization := "my-org",
  scalaVersion := "2.12.4",
  javaOptions += "-Dconfig.file=conf/application.dev.conf"
)

lazy val root = (project in file("."))
  .enablePlugins(PlayScala)
  .aggregate(server, client)
  .dependsOn(server, client)

lazy val common = (project in file("common"))
  .settings(
    name := "my-common",
    version := "1.0.0",

    libraryDependencies := commonDeps ++ Seq("com.typesafe.play" %% "play-json" % "2.6.7")
  )

lazy val server = (project in file("server"))
  .enablePlugins(PlayScala)
  .dependsOn(common)
  .settings(
    commonSettings,

    name := "my-server",
    version := "1.0.0",

    libraryDependencies := commonDeps ++ playDeps ++ slickDeps
  )

lazy val client = (project in file("client"))
  .enablePlugins(PlayScala)
  .dependsOn(common)
  .settings(
    commonSettings,

    name := "my-client",
    version := "1.1.13",

    libraryDependencies := Seq("org.typelevel" %% "cats" % "0.9.0") ++ commonDeps ++ playDeps ++ slickDeps
  )

通过切换到服务器项目project server并运行run运行应用程序时,出现以下错误消息:

[error] java.lang.ClassNotFoundException: play.core.server.DevServerStart
[error]         at java.base/java.net.URLClassLoader.findClass(Unknown Source)
[error]         at java.base/java.lang.ClassLoader.loadClass(Unknown Source)
[error]         at java.base/java.lang.ClassLoader.loadClass(Unknown Source)
[error]         at play.runsupport.Reloader$.startDevMode(Reloader.scala:227)
[error]         at play.sbt.run.PlayRun$.devModeServer$lzycompute$1(PlayRun.scala:95)
[error]         at play.sbt.run.PlayRun$.devModeServer$1(PlayRun.scala:79)
[error]         at play.sbt.run.PlayRun$.$anonfun$playRunTask$3(PlayRun.scala:102)
[error]         at play.sbt.run.PlayRun$.$anonfun$playRunTask$3$adapted(PlayRun.scala:65)
[error]         at scala.Function1.$anonfun$compose$1(Function1.scala:44)
[error]         at sbt.internal.util.$tilde$greater.$anonfun$$u2219$1(TypeFunctions.scala:39)
[error]         at sbt.std.Transform$$anon$4.work(System.scala:66)
[error]         at sbt.Execute.$anonfun$submit$2(Execute.scala:262)
[error]         at sbt.internal.util.ErrorHandling$.wideConvert(ErrorHandling.scala:16)
[error]         at sbt.Execute.work(Execute.scala:271)
[error]         at sbt.Execute.$anonfun$submit$1(Execute.scala:262)
[error]         at sbt.ConcurrentRestrictions$$anon$4.$anonfun$submitValid$1(ConcurrentRestrictions.scala:174)
[error]         at sbt.CompletionService$$anon$2.call(CompletionService.scala:36)
[error]         at java.base/java.util.concurrent.FutureTask.run(Unknown Source)
[error]         at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source)
[error]         at java.base/java.util.concurrent.FutureTask.run(Unknown Source)
[error]         at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
[error]         at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
[error]         at java.base/java.lang.Thread.run(Unknown Source)
[accuheat-server] $ [error] (Compile / run) java.lang.ClassNotFoundException: play.core.server.DevServerStart

似乎没有使用PlayScala插件,这是我第一次尝试在同一个项目中合并2个Play应用程序,因此将不胜感激。

谢谢

1 个答案:

答案 0 :(得分:2)

那是因为这样的行:

libraryDependencies := commonDeps ...

在libraryDependencies上使用:=会导致错误。我不知道为什么,但是将其更改为++=即可!