6

I am on a Linux Mint machine where I installed the latest version of Java (HotSpot VM 1.7.0_45) and using Gradle 1.8. I also have Groovy installed, version 1.8.6, but I think that does not matter as Gradle has its own groovy-all.jar.

My problem is that I could not compile my Groovy project using gradle because the JavaFX classes do not seem to be in the classpath. The errors are like this:

unable to resolve class javafx.scene.Node
 @ line 3, column 1.
   import javafx.scene.Node

I finally fixed this by adding the following horrible hard-coded path into my dependencies:

compile files( "/usr/lib/jvm/java-7-oracle/jre/lib/jfxrt.jar" )

Is there a better way to add JavaFX to Gradle's compilation classpath so that it is visible to all my projects without me having to add this to each one of them??

I have tried everything I could imagine:

  • added the jfxrt.jar to the standard JRE (I confirmed gradle is using my standard java to run) ext folder, so that I now can compile java classes with javac and run them with java (I know that in this version of Java the JavaFX jar should be already in the JDK's classpath, but I still couldn't RUN, as opposed to compile, my Java app before doing this).
  • also added a soft link to the same jar in the groovy classpath, so that I can do something like shown below from the groovy shell and it works:

    import javafx.application.Application as A ; println A

This also works in the Groovy Console.

It only does not work in Gradle!

Thanks for any help.

4

1 回答 1

7

使用JavaFX Gradle 插件

JavaFX Gradle 插件应该能够确定 JavaFX 运行时所在的位置,而无需执行手动的环境特定配置。

有关 JavaFX 类路径解析(与 Gradle 无关)的更多信息,请参阅: 使用 JavaFX 2.0 编译代码(使用命令行)

另请注意,如果您使用的是Oracle Java 8或更高版本,JavaFX 类现在位于 Oracle Java 实现的默认运行时类路径中。

顺便说一句,整个 JavaFX 系统的构建系统都是基于 Gradle 的,所以 JavaFX 和 Gradle 之间肯定没有不兼容的地方。

于 2013-10-23T22:12:34.137 回答