问题
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);
}
回答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.
来源:https://stackoverflow.com/questions/54344423/javafx-11-not-supporting-ecmascript6-and-css3