2

I have an JavaFX application that creates a new scene with a StackPane. Inside this StackPane, a label and a WebView are being added. When the WebEngine wants to load a page, however, it causes the application to crash without an error message.

I have a Maven project which includes Spring Boot as a parent and also the javafx modules, such as javafx-web as dependencies. I build it with the goal "package" and run the app via java -jar "C:\SomePath\demo\target\demo-0.0.1-SNAPSHOT.jar". As soon as the WebEngine tries to load a given page, the application closes without showing an error message in the cmd.exe.

The WebView is being created and access in the JavaFX application thread - I already checked that.

Here is my class 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();
    }

}

Here is the pom.xml I'm using:

<?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>

Does anyone know what causes the WebEngine to crash in this example project?

Here are some more details about the JDK and JAVA version I am using:

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)

Thank you in advance for any help.

With best regards, Husky

Husky
  • 71
  • 1
  • 7
  • Why do you think it crashes at all if there is no error message? As far as I can tell it isn't going to do anything at all. The JavaFX app uses JavaFX Application, not a SpringBoot Application. You are applying the SpringBoot plugin, not the JavaFX plugin. The SpringBoot plugin packages the app to run a SpringBoot Application, which you don't have, so there is nothing to do. Also, use a recent version of Java/JavaFX (e.g. 15). Info on integrating [JavaFX and SpringBoot](https://stackoverflow.com/questions/57887944/adding-spring-dependency-injection-in-javafx-jpa-repo-service). – jewelsea Sep 22 '20 at 20:30
  • The application freezes and it automatically closes. For this reason, I assume that the JVM crashes. It also generates a .dmp file. In the console however, there is no error message shown. – Husky Sep 25 '20 at 19:34
  • Try building and running the app without Spring. Does it work in your environment? Other than that, I don’t think you have supplied enough information, e.g. your SpringBoot application code. Without an [mcve], I don’t think you will get any assistance. – jewelsea Sep 25 '20 at 20:55
  • When I run the app in the IDE, there is no problem. For me, the code above is not working. Also, I have in this sample no SpringBoot application code. – Husky Sep 26 '20 at 00:28
  • I'm getting the exact same problem. In my IDE it runs just fine. When loading webview in a jar, JVM crashes with no error message. – FARS Apr 15 '22 at 06:07

1 Answers1

1

This is a known javafx issue. Fixed on version 17 or higher

FARS
  • 313
  • 6
  • 20