java -jar HelloFX.jar 在 Windows 上完美运行,但在 Linux 或 Raspberry pi 中无法运行

问题描述 投票:0回答:1

每当我在 Linux 或树莓派中运行 java -jar HelloFX.jar 命令时,该应用程序都会显示以下错误,我正在通过互联网搜索上个月的解决方案,但没有找到任何有效的解决方案。但是 Jar 文件在使用 JDK 21 的不同窗口中工作。我已经在 Raspberry pi 和我的 Linux 上安装了 JDK 21,其他 Java 文件运行良好,但是当我尝试运行 JavaFX jar 文件时,它显示这些错误。

jibon@jibon:~/Desktop $ java -jar HelloFX.jar 
Nov 27, 2023 1:24:11 PM com.sun.javafx.application.PlatformImpl startup
WARNING: Unsupported JavaFX configuration: classes were loaded from 'unnamed module @9efff14'
Graphics Device initialization failed for :  es2, sw
Error initializing QuantumRenderer: no suitable pipeline found
java.lang.RuntimeException: java.lang.RuntimeException: Error initializing QuantumRenderer: no suitable pipeline found
    at com.sun.javafx.tk.quantum.QuantumRenderer.getInstance(QuantumRenderer.java:283)
    at com.sun.javafx.tk.quantum.QuantumToolkit.init(QuantumToolkit.java:253)
    at com.sun.javafx.tk.Toolkit.getToolkit(Toolkit.java:263)
    at com.sun.javafx.application.PlatformImpl.startup(PlatformImpl.java:290)
    at com.sun.javafx.application.PlatformImpl.startup(PlatformImpl.java:162)
    at com.sun.javafx.application.LauncherImpl.startToolkit(LauncherImpl.java:651)
    at com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:671)
    at com.sun.javafx.application.LauncherImpl.lambda$launchApplication$2(LauncherImpl.java:196)
    at java.base/java.lang.Thread.run(Thread.java:1583)
Caused by: java.lang.RuntimeException: Error initializing QuantumRenderer: no suitable pipeline found
    at com.sun.javafx.tk.quantum.QuantumRenderer$PipelineRunnable.init(QuantumRenderer.java:95)
    at com.sun.javafx.tk.quantum.QuantumRenderer$PipelineRunnable.run(QuantumRenderer.java:125)
    ... 1 more
Exception in thread "main" java.lang.RuntimeException: No toolkit found
    at com.sun.javafx.tk.Toolkit.getToolkit(Toolkit.java:275)
    at com.sun.javafx.application.PlatformImpl.startup(PlatformImpl.java:290)
    at com.sun.javafx.application.PlatformImpl.startup(PlatformImpl.java:162)
    at com.sun.javafx.application.LauncherImpl.startToolkit(LauncherImpl.java:651)
    at com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:671)
    at com.sun.javafx.application.LauncherImpl.lambda$launchApplication$2(LauncherImpl.java:196)
    at java.base/java.lang.Thread.run(Thread.java:1583)

我使用 IntelliJ IDE 来构建 JavaFX 应用程序。正如我告诉你的,它可以在不同的窗口中完美运行。但是当我尝试在 Linux 或 Raspberry Pi 上运行它时,它向我显示了这些错误。
请给我一个完美的解决方案。

一些文件

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>

    <groupId>pro.jibon.apps.hellofx</groupId>
    <artifactId>HelloFX</artifactId>
    <version>1.0-SNAPSHOT</version>
    <name>HelloFX</name>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <junit.version>5.9.2</junit.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>com.pi4j</groupId>
            <artifactId>pi4j-core</artifactId>
            <version>1.3</version>
        </dependency>
        <dependency>
            <groupId>org.openjfx</groupId>
            <artifactId>javafx-controls</artifactId>
            <version>21-ea+24</version>
        </dependency>
        <dependency>
            <groupId>org.openjfx</groupId>
            <artifactId>javafx-fxml</artifactId>
            <version>21-ea+24</version>
        </dependency>

        <dependency>
            <groupId>org.junit.jupiter</groupId>
            <artifactId>junit-jupiter-api</artifactId>
            <version>${junit.version}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.junit.jupiter</groupId>
            <artifactId>junit-jupiter-engine</artifactId>
            <version>${junit.version}</version>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-shade-plugin</artifactId>
                <version>2.3</version>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>shade</goal>
                        </goals>
                        <configuration>
                            <transformers>
                                <transformer
                                        implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                                    <mainClass>pro.jibon.apps.hellofx.hellofx.Main</mainClass>
                                </transformer>
                            </transformers>
                            <filters>
                                <filter>
                                    <artifact>*:*</artifact>
                                    <excludes>
                                        <exclude>META-INF/*.SF</exclude>
                                        <exclude>META-INF/*.DSA</exclude>
                                        <exclude>META-INF/*.RSA</exclude>
                                    </excludes>
                                </filter>
                            </filters>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.11.0</version>
                <configuration>
                    <source>21</source>
                    <target>21</target>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.openjfx</groupId>
                <artifactId>javafx-maven-plugin</artifactId>
                <version>0.0.8</version>
                <executions>
                    <execution>
                        <!-- Default configuration for running with: mvn clean javafx:run -->
                        <id>default-cli</id>
                        <configuration>
                            <mainClass>pro.jibon.apps.hellofx.hellofx/pro.jibon.apps.hellofx.hellofx.Main
                            </mainClass>
                            <launcher>app</launcher>
                            <jlinkZipName>app</jlinkZipName>
                            <jlinkImageName>app</jlinkImageName>
                            <noManPages>true</noManPages>
                            <stripDebug>true</stripDebug>
                            <noHeaderFiles>true</noHeaderFiles>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-assembly-plugin</artifactId>
                <version>3.3.0</version>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>single</goal>
                        </goals>
                        <configuration>
                            <archive>
                                <manifest>
                                    <mainClass>pro.jibon.apps.hellofx.hellofx.Main</mainClass>
                                </manifest>
                            </archive>
                            <descriptorRefs>
                                <descriptorRef>jar-with-dependencies</descriptorRef>
                            </descriptorRefs>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>

HelloApplication.java

package pro.jibon.apps.hellofx.hellofx;

import javafx.application.Application;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.event.EventHandler;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.scene.Scene;
import javafx.scene.control.Alert;
import javafx.scene.control.Button;
import javafx.scene.input.KeyCombination;
import javafx.scene.input.MouseEvent;
import javafx.scene.input.TouchEvent;
import javafx.stage.Stage;
import com.pi4j.io.gpio.GpioController;
import com.pi4j.io.gpio.GpioFactory;
import com.pi4j.io.gpio.GpioPinDigitalOutput;
import com.pi4j.io.gpio.PinState;
import com.pi4j.io.gpio.RaspiPin;
import javafx.stage.StageStyle;
import javafx.stage.Window;
import javafx.stage.WindowEvent;

import java.io.IOException;


public class HelloApplication extends Application {
    @FXML
    private Button button1;
    @Override
    public void start(Stage stage) throws IOException {
        FXMLLoader fxmlLoader = new FXMLLoader(HelloApplication.class.getResource("hello-view.fxml"));
        Scene scene = new Scene(fxmlLoader.load(), stage.getMaxWidth(), stage.getMaxHeight());
        stage.setTitle("Hello!");
        stage.setScene(scene);
        stage.initStyle(StageStyle.UTILITY);
        stage.show();
        button1 = (Button) scene.lookup("#btn");
        button1.setText("Close");
        button1.setOnAction(mouseEvent -> {
            stage.close();
        });
        stage.setOnCloseRequest(windowEvent -> {
            Alert alert = new Alert(Alert.AlertType.ERROR);
            alert.setTitle("Wait");
            alert.setContentText("Are feeling okay by clicking me huh?");
            alert.setHeaderText("WTF yaar!");
//            alert.show();
            windowEvent.consume();
        });
        stage.setAlwaysOnTop(true);
        stage.setResizable(false);
        stage.setMaximized(true);
        stage.setResizable(false);
        stage.setFullScreen(true);
        stage.setFullScreenExitKeyCombination(KeyCombination.NO_MATCH);
        stage.fullScreenProperty().addListener((observable, oldValue, newValue) -> {
            stage.setFullScreen(true);
        });
    }

    public static void main(String[] args) {
        launch();
    }

    public static boolean isRunningOnRaspberryPi() {
        try {
            GpioController gpio = GpioFactory.getInstance();
            gpio.shutdown();
            return true;
        } catch (UnsatisfiedLinkError e) {
            return false;
        }
    }
}

HelloView.FXML

<?xml version="1.0" encoding="UTF-8"?>

<?import javafx.geometry.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.effect.*?>
<?import javafx.scene.layout.*?>

<VBox xmlns="http://javafx.com/javafx/11.0.14-internal" xmlns:fx="http://javafx.com/fxml/1">
     <padding>
         <Insets bottom="20.0" left="20.0" right="20.0" top="20.0" />
     </padding>
     <ToolBar nodeOrientation="LEFT_TO_RIGHT" prefHeight="40.0" prefWidth="200.0">
         <items>
             <Button mnemonicParsing="false" text="Button" />
             <Button mnemonicParsing="false" text="Button" />
             <Button mnemonicParsing="false" text="Button" />
             <Button mnemonicParsing="false" text="Button" />
             <Button mnemonicParsing="false" text="Button" />
         </items>
     </ToolBar>

     <Label fx:id="welcomeText" />
     <Button fx:id="btn" alignment="CENTER" text="Hello!">
      <effect>
         <Blend />
      </effect>
   </Button>
 </VBox>

Main.java

package pro.jibon.apps.hellofx.hellofx;

import pro.jibon.apps.hellofx.hellofx.*
        ;

public class Main {
    public static void main(String[] args) {
        HelloApplication.main(args);
    }
}

一些必要的截图

Windows 上的输出

Linux 上的输出

java linux javafx jar raspberry-pi
1个回答
0
投票

也许添加到您的 POM 会有所帮助

<dependency>
    <groupId>org.openjfx</groupId>
    <artifactId>javafx-graphics</artifactId>
    <version>{YOUR_VERSION}</version>
    <classifier>linux</classifier>
</dependency>
© www.soinside.com 2019 - 2024. All rights reserved.