42

How can I find out at runtime which version of JavaFX I'm using?

Jacob Schoen
  • 14,034
  • 15
  • 82
  • 102
dajood
  • 3,758
  • 9
  • 46
  • 68

3 Answers3

44

One of simple ways is to simply read the javafx.properties file located in your $JAVA_HOME/jre/lib directory.

I have Java 1.7 u9 installed at the moment. JavaFX bundled with it is v2.0.3 so the abovementioned file contains the following line:

javafx.runtime.version=2.0.3
DejanLekic
  • 18,787
  • 4
  • 46
  • 77
39
com.sun.javafx.runtime.VersionInfo.getRuntimeVersion();
Sergey Grinev
  • 34,078
  • 10
  • 128
  • 141
  • Can you, please, elaborate? Is there any output or exception? – Sergey Grinev Sep 04 '12 at 14:34
  • 1
    I don't have it in front of me, but in substance: Classloader exception, can't load com.sun.javafx.runtime.VersionInfo. And the program does not start. – assylias Sep 04 '12 at 14:49
  • 1
    This class is not available by default in Java 18. Code editor error message: *Package 'com.sun.javafx.runtime' is declared in module 'javafx.base', which does not export it to module 'com.example.fxdemo'* – Basil Bourque Mar 29 '22 at 22:45
  • 2
    @BasilBourque yep, this is way too old approach. Please use the system properties. – Sergey Grinev Mar 30 '22 at 14:24
24

System.getProperty( "javafx.runtime.version" )

You can get the javafx.runtime.version number from a System Property.

Call System.getProperty, passing the property name "javafx.runtime.version".

import javafx.application.Application;
import javafx.stage.Stage;
public class ReportVersion extends Application {
  public static void main(String[] args) { launch(args); }
  @Override public void start(Stage stage) {
    System.out.println("javafx.runtime.version: " + System.getProperty("javafx.runtime.version"));
    System.exit(0);
  }
}

Note that the System Property access method may cause a security exception if an unsigned application is embedded in a browser or accessed via WebStart, so Sergey's com.sun call may be better even though all com.sun calls are deprecated and not part of the official JavaFX public API.

Update

@assylias comments on Sergey's answer would seem to indicate that Sergey's com.sun may cause a security exception if an unsigned application is embedded in a browser or accessed via WebStart. So perhaps there is no good solution to determining the javafx runtime version when running under those specific conditions.


Trashgod wrote a version check script which works similarly to this answer and provides a couple more pieces of diagnostic version information from the environment. The script comes with an ant build script, but the version check application is just a plain JavaFX application. So, you can ignore the ant build script if you wish and can execute the utility in any compatible JavaFX environment.

Basil Bourque
  • 303,325
  • 100
  • 852
  • 1,154
jewelsea
  • 150,031
  • 14
  • 366
  • 406
  • 1
    This does not work in a sandboxed applet due to lack of permissions. The slightly modified version `System.getProperty("javafx.runtime.version")` does also not work with this error: `java.security.AccessControlException: access denied ("java.util.PropertyPermission" "javafx.runtime.version" "read")` – Frederic Leitenberger Oct 15 '14 at 16:23