StackPane を使用して新しいシーンを作成する JavaFX アプリケーションがあります。この StackPane 内に、ラベルと WebView が追加されています。ただし、WebEngine がページをロードしようとすると、エラー メッセージなしでアプリケーションがクラッシュします。
Spring Boot を親として含み、javafx-web などの javafx モジュールを依存関係として含む Maven プロジェクトがあります。目標の「パッケージ」でビルドし、Java -jar "C:\SomePath\demo\target\demo-0.0.1-SNAPSHOT.jar" を介してアプリを実行します。WebEngine が特定のページをロードしようとするとすぐに、アプリケーションは cmd.exe にエラー メッセージを表示せずに終了します。
WebView が作成され、JavaFX アプリケーション スレッドでアクセスされます - 私はすでにそれを確認しました。
ここに私のクラス MyApp.jar があります:
package com.test.demo;
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.scene.layout.StackPane;
import javafx.scene.web.WebEngine;
import javafx.scene.web.WebView;
import javafx.stage.Stage;
/**
* JavaFX App
*/
public class MyApp extends Application {
@Override
public void start(Stage stage) {
WebView webView = new WebView();
WebEngine webEngine = webView.getEngine();
webEngine.load("https://stackoverflow.com");
Label l = new Label("this is my label.");
Scene scene = new Scene(new StackPane(webView, l), 640, 480);
stage.setScene(scene);
stage.show();
}
public static void main(String[] args) {
launch();
}
}
私が使用しているpom.xmlは次のとおりです。
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.3.4.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.test</groupId>
<artifactId>demo</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>demo</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>11</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-controls</artifactId>
<version>11.0.2</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.openjfx/javafx-web -->
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-web</artifactId>
<version>11.0.2</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.openjfx/javafx-base -->
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-base</artifactId>
<version>11.0.2</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.openjfx/javafx-graphics -->
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-graphics</artifactId>
<version>11.0.2</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.openjfx/javafx-media -->
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-media</artifactId>
<version>11.0.2</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
このサンプル プロジェクトで WebEngine がクラッシュする原因を知っている人はいますか?
私が使用しているJDKとJAVAのバージョンに関する詳細は次のとおりです。
C:\Users>javac -version
javac 11.0.8
C:\Users>java -version
java version "11.0.8" 2020-07-14 LTS
Java(TM) SE Runtime Environment 18.9 (build 11.0.8+10-LTS)
Java HotSpot(TM) 64-Bit Server VM 18.9 (build 11.0.8+10-LTS, mixed mode)
よろしくお願いします。
敬具、ハスキー