How to get the version number of JavaFX?

2019-01-07 14:42发布

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

3条回答
ら.Afraid
2楼-- · 2019-01-07 14:55
com.sun.javafx.runtime.VersionInfo.getRuntimeVersion();
查看更多
聊天终结者
3楼-- · 2019-01-07 14:55

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
查看更多
乱世女痞
4楼-- · 2019-01-07 15:05

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

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.getProperties().get("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.

查看更多
登录 后发表回答