Scala sbt构建因Javafx而失败

时间:2019-03-02 12:12:00

标签: java scala javafx sbt

我刚刚开始使用Scala教程。
编译时出现以下错误。
我该如何解决?

"/Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home/bin/java" --add-modules javafx.base,javafx.graphics --add-reads javafx.base=ALL-UNNAMED --add-reads javafx.graphics=ALL-UNNAMED "-javaagent:/Applications/IntelliJ IDEA CE.app/Contents/lib/idea_rt.jar=55919:/Applications/IntelliJ IDEA CE.app/Contents/bin" -Dfile.encoding=UTF-8 -classpath "/Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home/lib/charsets.jar:/Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home/lib/deploy.jar:/Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home/lib/ext/cldrdata.jar:/Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home/lib/ext/dnsns.jar:/Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home/lib/ext/jaccess.jar:/Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home/lib/ext/jfxrt.jar:/Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home/lib/ext/localedata.jar:/Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home/lib/ext/nashorn.jar:/Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home/lib/ext/sunec.jar:/Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home/lib/ext/sunjce_provider.jar:/Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home/lib/ext/sunpkcs11.jar:/Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home/lib/ext/zipfs.jar:/Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home/lib/javaws.jar:/Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home/lib/jce.jar:/Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home/lib/jfr.jar:/Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home/lib/jfxswt.jar:/Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home/lib/jsse.jar:/Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home/lib/management-agent.jar:/Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home/lib/plugin.jar:/Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home/lib/resources.jar:/Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home/lib/rt.jar:/Volumes/Samsung_T5/Dev/ScalaProjects/nightcoreplayer/target/scala-2.12/classes:/Users/shunsuke/.ivy2/cache/org.openjfx/javafx-base/jars/javafx-base-11-ea+25-mac.jar:/Users/shunsuke/.sbt/boot/scala-2.12.7/lib/scala-library.jar:/Users/shunsuke/.ivy2/cache/org.openjfx/javafx-web/jars/javafx-web-11-ea+25-mac.jar:/Users/shunsuke/.ivy2/cache/org.openjfx/javafx-media/jars/javafx-media-11-ea+25-mac.jar:/Users/shunsuke/.ivy2/cache/org.openjfx/javafx-graphics/jars/javafx-graphics-11-ea+25-mac.jar:/Users/shunsuke/.ivy2/cache/org.openjfx/javafx-fxml/jars/javafx-fxml-11-ea+25-mac.jar:/Users/shunsuke/.ivy2/cache/org.openjfx/javafx-controls/jars/javafx-controls-11-ea+25-mac.jar" -p /Users/shunsuke/.ivy2/cache/org.openjfx/javafx-base/jars/javafx-base-11-ea+25-mac.jar:/Users/shunsuke/.ivy2/cache/org.openjfx/javafx-graphics/jars/javafx-graphics-11-ea+25-mac.jar jp.ed.nnn.nightcoreplayer.Main
Unrecognized option: --add-modules
Error: Could not create the Java Virtual Machine.
Error: A fatal exception has occurred. Program will exit.

Process finished with exit code 1

sbt build fails

build.sbt

lazy val commonSettings = Seq(
  version := "1.0.0-SNAPSHOT",
  organization := "jp.ed.nnn",
  scalaVersion := "2.12.7"
)

val osName: SettingKey[String] = SettingKey[String]("osName")

osName := (System.getProperty("os.name") match {
  case name if name.startsWith("Linux") => "linux"
  case name if name.startsWith("Mac") => "mac"
  case name if name.startsWith("Windows") => "win"
  case _ => throw new Exception("Unknown platform!")
})

libraryDependencies += "org.openjfx" % "javafx-base" % "11-ea+25" classifier osName.value
libraryDependencies += "org.openjfx" % "javafx-controls" % "11-ea+25" classifier osName.value
libraryDependencies += "org.openjfx" % "javafx-fxml" % "11-ea+25" classifier osName.value
libraryDependencies += "org.openjfx" % "javafx-graphics" % "11-ea+25" classifier osName.value
libraryDependencies += "org.openjfx" % "javafx-web" % "11-ea+25" classifier osName.value
libraryDependencies += "org.openjfx" % "javafx-media" % "11-ea+25" classifier osName.value

1 个答案:

答案 0 :(得分:1)

您可能未在IDEA中使用正确版本的JDK。

download page安装一个JDK 8二进制文件,并按照instructions进行操作,以了解如何定义SDK。

有关兼容的JDK,请参见scala compatible overview