当前位置: 首页 > 知识库问答 >
问题:

无法生成跨平台javaFX应用程序

诸葛乐逸
2023-03-14

我似乎无法从javaFX应用程序中生成跨平台构建。

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:280)
    at com.sun.javafx.tk.quantum.QuantumToolkit.init(QuantumToolkit.java:244)
    at com.sun.javafx.tk.Toolkit.getToolkit(Toolkit.java:261)
    at com.sun.javafx.application.PlatformImpl.startup(PlatformImpl.java:267)
    at com.sun.javafx.application.PlatformImpl.startup(PlatformImpl.java:158)
    at com.sun.javafx.application.LauncherImpl.startToolkit(LauncherImpl.java:658)
    at com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:678)
    at com.sun.javafx.application.LauncherImpl.lambda$launchApplication$2(LauncherImpl.java:195)
    at java.base/java.lang.Thread.run(Thread.java:832)
Caused by: java.lang.RuntimeException: Error initializing QuantumRenderer: no suitable pipeline found
    at com.sun.javafx.tk.quantum.QuantumRenderer$PipelineRunnable.init(QuantumRenderer.java:94)
    at com.sun.javafx.tk.quantum.QuantumRenderer$PipelineRunnable.run(QuantumRenderer.java:124)
    ... 1 more
Exception in thread “main” java.lang.RuntimeException: No toolkit found
    at com.sun.javafx.tk.Toolkit.getToolkit(Toolkit.java:273)
    at com.sun.javafx.application.PlatformImpl.startup(PlatformImpl.java:267)
    at com.sun.javafx.application.PlatformImpl.startup(PlatformImpl.java:158)
    at com.sun.javafx.application.LauncherImpl.startToolkit(LauncherImpl.java:658)
    at com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:678)
    at com.sun.javafx.application.LauncherImpl.lambda$launchApplication$2(LauncherImpl.java:195)
    at java.base/java.lang.Thread.run(Thread.java:832)

在实际的FX应用程序之前,还有一个启动器,这是清单所指向的地方。这就是pom的样子。

<profiles>
    <profile>
        <id>linux</id>
        <dependencies>
            <dependency>
                <groupId>org.openjfx</groupId>
                <artifactId>javafx-controls</artifactId>
                <version>11</version>
                <classifier>linux</classifier>
            </dependency>
            <dependency>
                <groupId>org.openjfx</groupId>
                <artifactId>javafx-fxml</artifactId>
                <version>11</version>
                <classifier>linux</classifier>
            </dependency>
        </dependencies>
    </profile>
    <profile>
        <id>mac</id>
        <dependencies>
            <dependency>
                <groupId>org.openjfx</groupId>
                <artifactId>javafx-controls</artifactId>
                <version>11</version>
                <classifier>mac</classifier>
            </dependency>
            <dependency>
                <groupId>org.openjfx</groupId>
                <artifactId>javafx-fxml</artifactId>
                <version>11</version>
                <classifier>mac</classifier>
            </dependency>
        </dependencies>
    </profile>
    <profile>
        <id>win</id>
        <dependencies>
            <dependency>
                <groupId>org.openjfx</groupId>
                <artifactId>javafx-controls</artifactId>
                <version>11</version>
                <classifier>win</classifier>
            </dependency>
            <dependency>
                <groupId>org.openjfx</groupId>
                <artifactId>javafx-fxml</artifactId>
                <version>11</version>
                <classifier>win</classifier>
            </dependency>
        </dependencies>
    </profile>
</profiles>

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.8.0</version>
            <configuration>
                <release>11</release>
            </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">
                                <manifestEntries>
                                    <Main-Class>org.log.Launcher</Main-Class>
                                </manifestEntries>
                            </transformer>
                        </transformers>
                    </configuration>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>

我还注意到,无论我选择什么概要文件,它总是生成linux版本,我可以看到这个maven日志:

[WARNING] javafx-controls-11-win.jar, javafx-graphics-11-linux.jar, javafx-fxml-11-linux.jar, LogAnalyzer-1.0-SNAPSHOT.jar, javafx-base-11-linux.jar, javafx-controls-11-linux.jar, javafx-fxml-11-win.jar define 1 overlapping classes: 
[WARNING]   - module-info
[WARNING] javafx-controls-11-win.jar, javafx-controls-11-linux.jar define 1216 overlapping classes: 
[WARNING]   - com.sun.javafx.scene.control.TableColumnBaseHelper$TableColumnBaseAccessor
[WARNING]   - javafx.scene.control.ComboBoxBase
[WARNING]   - javafx.scene.control.skin.ColorPickerSkin$StyleableProperties$2
[WARNING]   - com.sun.javafx.scene.control.inputmap.InputMap$KeyMappingInterceptor
[WARNING]   - javafx.scene.control.cell.ChoiceBoxTreeTableCell
[WARNING]   - javafx.scene.control.TableCell$3
[WARNING]   - javafx.scene.control.skin.ProgressBarSkin$StyleableProperties$1
[WARNING]   - javafx.scene.control.DialogPane$2
[WARNING]   - javafx.scene.control.skin.ToolBarSkin$4
[WARNING]   - javafx.scene.control.skin.ColorPickerSkin$3
[WARNING]   - 1206 more...
[WARNING] javafx-fxml-11-linux.jar, javafx-fxml-11-win.jar define 80 overlapping classes: 
[WARNING]   - com.sun.javafx.fxml.expression.ExpressionValue$KeyPathMonitor
[WARNING]   - javafx.fxml.FXMLLoader$RootElement
[WARNING]   - com.sun.javafx.fxml.expression.Expression$Parser$TokenType
[WARNING]   - javafx.fxml.FXMLLoader$DefineElement
[WARNING]   - javafx.fxml.Initializable
[WARNING]   - javafx.fxml.FXMLLoader$ControllerMethodEventHandler
[WARNING]   - com.sun.javafx.fxml.BeanAdapter
[WARNING]   - javafx.fxml.FXMLLoader$ControllerAccessor$1
[WARNING]   - javafx.fxml.JavaFXBuilderFactory$ObjectBuilderWrapper$ObjectBuilder
[WARNING]   - javafx.fxml.FXML
[WARNING]   - 70 more...
[WARNING] maven-shade-plugin has detected that some class files are
[WARNING] present in two or more JARs. When this happens, only one
[WARNING] single version of the class is copied to the uber jar.
[WARNING] Usually this is not harmful and you can skip these warnings,
[WARNING] otherwise try to manually exclude artifacts based on
[WARNING] mvn dependency:tree -Ddetail=true and the above output.
[WARNING] See http://maven.apache.org/plugins/maven-shade-plugin/

我一直在看其他的帖子和查看一些视频,这似乎也发生在其他人身上,但看起来有点奇怪。同样奇怪的是,当我为windows生成时,在生成的JAR中看不到任何.dll文件。

正如其他帖子中所建议的,我有一个Launcher类,它调用扩展Application的实际类:

public class Launcher {
    public static void main(String[] args) {
        App.main(args);
    }
}

和JavaFX类:

public class App extends Application {

    public static void main(String[] args) {
        Application.launch();
    }
        
    @Override
    public void start(Stage stage) throws IOException {
        ...
    }
}

我现在从pom中删除了概要文件,所以在编译时,maven应该接受所有的依赖项(mac、linux和win),但似乎它仍然只生成linux依赖项(我正在linux上运行,我猜这与它有关),因为如果我打开jar文件,我看不到任何.dll文件,而且它仍然不能在mac上工作。以下是我的完整POM:

<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 http://maven.apache.org/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>org.log</groupId>
    <artifactId>LogAnalyzer</artifactId>
    <packaging>jar</packaging>
    <version>1.0-SNAPSHOT</version>

<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <maven.compiler.source>11</maven.compiler.source>
    <maven.compiler.target>11</maven.compiler.target>
</properties>

<dependencies>
    <dependency>
        <groupId>org.openjfx</groupId>
        <artifactId>javafx-controls</artifactId>
        <version>11</version>
        <classifier>linux</classifier>
    </dependency>
    <dependency>
        <groupId>org.openjfx</groupId>
        <artifactId>javafx-fxml</artifactId>
        <version>11</version>
        <classifier>linux</classifier>
    </dependency>
    <dependency>
        <groupId>org.openjfx</groupId>
        <artifactId>javafx-controls</artifactId>
        <version>11</version>
        <classifier>mac</classifier>
    </dependency>
    <dependency>
        <groupId>org.openjfx</groupId>
        <artifactId>javafx-fxml</artifactId>
        <version>11</version>
        <classifier>mac</classifier>
    </dependency>
    <dependency>
        <groupId>org.openjfx</groupId>
        <artifactId>javafx-controls</artifactId>
        <version>11</version>
        <classifier>win</classifier>
    </dependency>
    <dependency>
        <groupId>org.openjfx</groupId>
        <artifactId>javafx-fxml</artifactId>
        <version>11</version>
        <classifier>win</classifier>
    </dependency>
    <dependency>
        <groupId>org.apache.commons</groupId>
        <artifactId>commons-csv</artifactId>
        <version>1.6</version>
    </dependency>
    <dependency>
        <groupId>org.junit.jupiter</groupId>
        <artifactId>junit-jupiter-api</artifactId>
        <version>5.7.0</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.hamcrest</groupId>
        <artifactId>hamcrest</artifactId>
        <version>2.2</version>
        <scope>test</scope>
    </dependency>
</dependencies>

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.8.0</version>
            <configuration>
                <release>11</release>
            </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">
                                <manifestEntries>
                                    <Main-Class>org.log.Launcher</Main-Class>
                                </manifestEntries>
                            </transformer>
                        </transformers>
                    </configuration>
                </execution>
            </executions>
        </plugin>

    </plugins>
</build>

共有1个答案

斜淳
2023-03-14

正如@JewelSea的一个评论中提供的一个链接所建议的,诀窍是单独地显式添加每个平台的图形模块。

<dependencies>
    <dependency>
        <groupId>org.openjfx</groupId>
        <artifactId>javafx-controls</artifactId>
        <version>11</version>
    </dependency>
    <dependency>
        <groupId>org.openjfx</groupId>
        <artifactId>javafx-fxml</artifactId>
        <version>11</version>
    </dependency>
    <dependency>
        <groupId>org.openjfx</groupId>
        <artifactId>javafx-graphics</artifactId>
        <version>11</version>
        <classifier>win</classifier>
    </dependency>
    <dependency>
        <groupId>org.openjfx</groupId>
        <artifactId>javafx-graphics</artifactId>
        <version>11</version>
        <classifier>linux</classifier>
    </dependency>
    <dependency>
        <groupId>org.openjfx</groupId>
        <artifactId>javafx-graphics</artifactId>
        <version>11</version>
        <classifier>mac</classifier>
    </dependency>
</dependencies>

它生成了一个fat jar,我终于可以看到里面的.dll文件了。在linux和mac上试过,它在两个平台上都能工作。

 类似资料:
  • 我需要为ant创建构建文件来构建我的,我已经搜索了很多,但没有任何帮助。它仍然显示错误并且不编译。当我尝试运行jar文件时,jar文件无法被删除。这里是 这里是错误

  • ASP 应用程序可在运行 Windows NT 4.0 或 Windows 95 及其更新版本的操作系统的计算机上运行。另外,可在 Macintosh 上运行 streamline 版本的 ASP。因为在 Windows 95 和 Macintosh 上的 Personal Web Server 是为个人发布设计的,所以在对 ASP 应用的支持方面有些不同。您可以在 Windows NT Work

  • 作者:陈希章 发表于 2017年6月25日 谈一谈.NET 的跨平台 终于要写到这一篇了。跨平台的支持可以说是 Office 365 平台在设计伊始就考虑的目标。我在前面的文章已经提到过了,Microsoft Graph 服务针对一些主流的开源平台(主要用来做跨平台应用)都有支持,例如 python,nodejs 等。他们真的非常好用,与此同时我虽然对他们也有一定的了解,但要跟我最熟悉的 Micr

  • 是否有计划开发用于跨平台交互的CordaRPCOps,例如will there,或者是我可以使用Python或中的RPC连接到Corda节点的方法。网络?

  • 我正在寻找使用ReactNative或原生平台(iOS和Android)创建一个BLE移动应用程序的利弊。 我应该遵循哪种方法?有人能和ReactNative分享他们的经验吗?我在这两个原生平台上都工作过,它给了我很好的效果,但是对于我的新项目,我考虑的是ReactNative,因为它有单一的代码库,相对来说比在iOS和Android上单独工作花费的精力要少。 BLE应用程序也有这些优势吗?或者它

  • 多平台支持 Mpx支持在多个小程序平台中进行增强,目前支持的小程序平台包括微信,支付宝,百度,qq和头条,不过自2.0版本后,Mpx支持了以微信增强语法为base的跨平台输出,实现了一套业务源码在多端输出运行的能力,大大提升了多小程序平台业务的开发效率,详情可以查看template增强特性 不同平台上的模板增强指令按照平台的指令风格进行设计,文档和代码示例为了方便统一采用微信小程序下的书写方式。