gpt4 book ai didi

maven - 在 ubuntu 上运行 javafx 跨平台 .jar

转载 作者:行者123 更新时间:2023-12-04 19:05:15 24 4
gpt4 key购买 nike

这个问题在这里已经有了答案:





Maven Shade JavaFX runtime components are missing

(1 个回答)


3个月前关闭。




我使用 maven shade 插件创建了跨平台的 .jar 文件。这个 jar 在 Windows 上运行良好,但是当我尝试在 ubuntu 上运行它时,我得到一个异常:

java.lang.ClassNotFoundException: com.sun.glass.ui.gtk.GtkPlatformFactory
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:641)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:188)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:520)
at java.base/java.lang.Class.forName0(Native Method)
at java.base/java.lang.Class.forName(Class.java:375)
at com.sun.glass.ui.PlatformFactory.getPlatformFactory(PlatformFactory.java:42)
at com.sun.glass.ui.Application.run(Application.java:145)
at com.sun.javafx.tk.quantum.QuantumToolkit.startup(QuantumToolkit.java:281)
at com.sun.javafx.application.PlatformImpl.startup(PlatformImpl.java:288)
at com.sun.javafx.application.PlatformImpl.startup(PlatformImpl.java:160)
at com.sun.javafx.application.LauncherImpl.startToolkit(LauncherImpl.java:661)
at com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:681)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication$2(LauncherImpl.java:198)
at java.base/java.lang.Thread.run(Thread.java:833)
Failed to load Glass factory class
Exception in thread "main" java.lang.NullPointerException: Cannot invoke "com.sun.glass.ui.PlatformFactory.createApplication()" because the return value of "com.sun.glass.ui.PlatformFactory.getPlatformFactory()" is null
at com.sun.glass.ui.Application.run(Application.java:145)
at com.sun.javafx.tk.quantum.QuantumToolkit.startup(QuantumToolkit.java:281)
at com.sun.javafx.application.PlatformImpl.startup(PlatformImpl.java:288)
at com.sun.javafx.application.PlatformImpl.startup(PlatformImpl.java:160)
at com.sun.javafx.application.LauncherImpl.startToolkit(LauncherImpl.java:661)
at com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:681)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication$2(LauncherImpl.java:198)
at java.base/java.lang.Thread.run(Thread.java:833)
我已经安装了gtk:
sudo apt-get install libgtk-3-dev
...和openjfx:
sudo apt-get install openjfx
......但它没有帮助。
我的 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>sudoku</groupId>
<artifactId>mega_sudoku</artifactId>
<version>1</version>
<name>mega_sudoku</name>

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

<dependencies>
<!-- controls -->
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-controls</artifactId>
<version>17-ea+11</version>
<classifier>win</classifier>
</dependency>

<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-controls</artifactId>
<version>17-ea+11</version>
<classifier>linux</classifier>
</dependency>

<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-controls</artifactId>
<version>17-ea+11</version>
<classifier>mac</classifier>
</dependency>


<!-- openjfx -->
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-fxml</artifactId>
<version>17-ea+11</version>
<classifier>win</classifier>
</dependency>

<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-fxml</artifactId>
<version>17-ea+11</version>
<classifier>linux</classifier>
</dependency>

<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-fxml</artifactId>
<version>17-ea+11</version>
<classifier>mac</classifier>
</dependency>

</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>17</source>
<target>17</target>
</configuration>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.0.0</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<transformers>
<transformer
implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>mega_sudoku.main.JarLauncher</mainClass>
</transformer>
</transformers>
<finalName>mega_sudoku</finalName>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
java --版本:
openjdk 17.0.2 2022-01-18
OpenJDK Runtime Environment (build 17.0.2+8-Ubuntu-120.04)
OpenJDK 64-Bit Server VM (build 17.0.2+8-Ubuntu-120.04, mixed mode, sharing)

这是我的 .jar 的问题,还是我需要对我的 ubuntu jdk 配置做一些事情?
我怎么解决这个问题?谢谢你的帮助。

最佳答案

我通过将此依赖项添加到 pom.xml 解决了我的问题

        <!-- media -->
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-media</artifactId>
<version>17-ea+11</version>
<classifier>win</classifier>
</dependency>

<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-media</artifactId>
<version>17-ea+11</version>
<classifier>linux</classifier>
</dependency>

<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-media</artifactId>
<version>17-ea+11</version>
<classifier>mac</classifier>
</dependency>


<!-- graphics -->
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-graphics</artifactId>
<version>17-ea+11</version>
<classifier>win</classifier>
</dependency>

<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-graphics</artifactId>
<version>17-ea+11</version>
<classifier>linux</classifier>
</dependency>

<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-graphics</artifactId>
<version>17-ea+11</version>
<classifier>mac</classifier>
</dependency>

关于maven - 在 ubuntu 上运行 javafx 跨平台 .jar,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71721026/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com