The goal is to have a standalone Play Framework (2.2) application having an additional status window open containing some javafx (javafx-8) elements.

Since JavaFX classes are now on the default runtime classpath for an Oracle Java 8 implementation using javafx.* in my classes and compiling with sbt should just be fine.

However sbt can't find these classes and quits with

play.api.UnexpectedException: Unexpected exception[NoClassDefFoundError: javafx/application/Application]

when executing

..\path-to-play-framework-2.2\play project run

The best way to fix this problem seems to be the modification of build.sbt in the project directory. What can I do to add the missing (class) path?

有帮助吗?

解决方案

Sadly JavaFX doesn't link that easily to an sbt build. You need to set your JAVA_HOME environment variable and do modifications to your build file.

Here I have a repository where this is set up. The important bit if you are using an sbt build rather than a scala build is this one:

unmanagedJars in Compile += Attributed.blank(
  file(System.getenv("JAVA_HOME") + "/jre/lib/jfxrt.jar")),

fork in run := true

The reason for this is that jfxrt.jar is the archive containing the JavaFX runtime and it is not included in the classpath of an sbt project by default.

其他提示

Anotherway is to set the Classpath for sbt. This can be done on the machines which can't resolve JavaFX.

SBT_OPTS="-Xbootclasspath/p:/usr/share/java/openjfx/jre/lib/ext/jfxrt.jar"
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top