1

I am creating a web browsing exp with some drawing tool with JAVA FX 11 but while trying to load the javascript code which has let and const used these variables are simply getting ignored and throwing the exceptions. I am using maven 3.8.0, Java 1.8 and JavaFX 11.

The code is as follows:

<dependency>
    <groupId>org.openjfx</groupId>
    <artifactId>javafx-controls</artifactId>
    <version>12-ea+9</version>
</dependency>
<dependency>
    <groupId>org.openjfx</groupId>
    <artifactId>javafx-web</artifactId>
    <version>12-ea+9</version>
</dependency>
<dependency>
    <groupId>org.openjfx</groupId>
    <artifactId>javafx-swing</artifactId>
    <version>12-ea+9</version>
</dependency>
<dependency>
    <groupId>org.openjfx</groupId>
    <artifactId>javafx-fxml</artifactId>
    <version>12-ea+9</version>
</dependency>

and Java Code

public static void main(String[] urls) {
        String javaVersion = System.getProperty("java.version");
        String javafxVersion = System.getProperty("javafx.version");
        System.out.println(javaVersion + " java....... fx........ " + javafxVersion);
        Application.launch(urls);
    }

    @Override
    public void start(Stage stage) throws Exception {
        Parameters parameters = getParameters();
        List<String> raw = parameters.getRaw();
        String url = "http://example.com/";
        if (raw.size() != 0) {
            url = raw.get(0);
        }
        /*
         * WebConsoleListener.setDefaultListener((webView, message, lineNumber,
         * sourceId) -> { System.out.println(message + "[at " + lineNumber + "] [in " +
         * sourceId + "]"); });
         */
        Pane root = new Pane();

        WebView webView = new WebView();
        WebEngine webEngine = webView.getEngine();

        // Load the Google web page
        webEngine.load(url);
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();

        Scene scene = new Scene(root);
        stage.setScene(scene);
        stage.setTitle("IWB");
        stage.show();

        // mainStage = stage;
        root.getChildren().add(webView);
        webView.setMinSize((screenSize.getWidth() - 120), (screenSize.getHeight() - 60));
        btns.setMinHeight(screenSize.getHeight() - 60);

        stage.setOnCloseRequest(e -> {
            // Platform.exit();
            // System.exit(0);
        });
        // Platform.setImplicitExit(false);
    }
fabian
  • 80,457
  • 12
  • 86
  • 114
Ullas Hunka
  • 2,119
  • 1
  • 15
  • 28
  • take a look at this question to determine the webkit version https://stackoverflow.com/questions/23214913/version-of-webkit-in-javafx-8-webview This should allow you to determine the features of that webkit version – keuleJ Jan 24 '19 at 10:43
  • 1
    Are you really using Java 8 with JavaFX 11? – José Pereda Jan 24 '19 at 11:00
  • Its a rnd and I am trying to run java 8 and javafx 11 together – Ullas Hunka Jan 24 '19 at 11:06
  • 1
    Don't know what that is, but good luck mixing Java 8 and JavaFX 11 – José Pereda Jan 24 '19 at 12:12
  • I came across some restrictions as my project which is already built in with java 8 using NameService which is deprecated after java 9 so I have to use java 8 for the project but some features require Javafx-11. So using it – Ullas Hunka Jan 25 '19 at 06:32
  • You can compile with Java 8 codelevel, while running with Java 11. Since Java 11 doesn't come with Java FX any longer, you have to explicitly package and distribute FX11 with your app and set `java.library.path` to its location. In regards to deprecated features... they should be OK for now. On the other hand, any removed features will break. For this reason, you may need to use reflection to interrogate the capabilities when mixing old codelevels with newer frameworks in the edgecase that those API calls that have been removed. – tresf Jun 11 '20 at 17:17
  • ... a code example where removed fx8 calls are mixed with fx11: https://github.com/qzind/tray/blob/76f40c3540e2388f6e77adcfa4874635a78bab1e/src/qz/printer/action/WebApp.java#L410-L421 – tresf Jun 11 '20 at 17:21

1 Answers1

1

I am using maven 3.8.0, Java 1.8 and JavaFX 11.

In short, use the latest Java 8. Java seems to be updating WebKit on that version, so newer versions will yield newer features. Read the below for the breakdown, specifically the differences between 8u5 and 8u251.

OpenJDK 11

  • JavaFX 11.0.2: WebKit Version 606.1 (Safari 12.x)
  • JavaFX 15-ea+3: WebKit Version 609.1 (Safari 13.x)
    • Note: Despite the name, JavaFX 15 is JDK11 compatible

Oracle Java 8

  • Java 8u5: WebKit Version 537.44 (Safari 7.x)
  • Java 8u251: WebKit Version 609.1 (Safari 13.x)

Some useful information:

  • Oracle Java 1.8 comes with its own bundled Java FX version, which generally can't be overridden. To use Java FX11, you will need to run the project with Java 11 and set the System property java.library.path to the location of the FX framework.
  • Version obtained using web.getEngine().getUserAgent() technique per https://stackoverflow.com/a/23228558/3196753
  • Assumes WebKit ~= Safari. Safari's has ECMAScript 6 support since Safari 10.
  • Warning: There are serious commercial licensing implications to using Oracle's Java. More about that here: Java Is Still Free 2.0.3. It's recommended to use OpenJDK 11 if this license causes issues with your app. The article has several providers that are available without these commercial licensing restrictions.
tresf
  • 7,103
  • 6
  • 40
  • 101