Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gradle fails to find JavaFX classes

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.

like image 697
Renato Avatar asked Oct 23 '13 21:10

Renato


1 Answers

Use the JavaFX Gradle Plugin.

The JavaFX Gradle Plugin should be able to work out where the JavaFX runtime is located without you having to perform manual, environment specific configuration.

For further information on JavaFX classpath resolution (not Gradle related), see: Compile code using JavaFX 2.0 (using command line).

Also note, if you are using Oracle Java 8 or newer, JavaFX classes are now on the default runtime classpath for an Oracle Java implementation.

Incidentally, the build system for the entire JavaFX system is based on Gradle, so there is definitely no incompatibility between JavaFX and Gradle.

like image 175
jewelsea Avatar answered Nov 07 '22 17:11

jewelsea