相关疑难解决方法(0)

如何使用 GraalVM 和 JavaFX 在 Maven 中编译本机映像?

我有一个 JavaFX 项目,想使用 GraalVM Java 虚拟机和相关的 Native-Image 工具将其编译为 Linux 二进制文件。我正在使用 GraalVM Java 11 版本 20.1.0 和通过 Maven 添加的 Native Image Maven 插件来实现这一点。

<plugin>
    <groupId>com.oracle.substratevm</groupId>
    <artifactId>native-image-maven-plugin</artifactId>
    <version>19.2.1</version>
    <configuration>
        <mainClass>sample.NewMain</mainClass>
        <imageName>sample</imageName>
        <buildArgs>
            -H:ReflectionConfigurationFiles=/home/user/Documents/Projects/TestProject/src/main/java/sample/reflect-config.json -H:+ReportExceptionStackTraces
        </buildArgs>
    </configuration>
    <executions>
        <execution>
            <goals>
                <goal>native-image</goal>
            </goals>
            <phase>package</phase>
        </execution>
    </executions>
</plugin>
Run Code Online (Sandbox Code Playgroud)

最初,我收到一条错误消息,指出Warning: Aborting stand-alone image build due to reflection use without configuration.我使用 Native Image 跟踪代理生成用于反射的配置文件,我将其传递到编译器插件中,如下所示: -H:ReflectionConfigurationFiles=/home/user/Documents/Projects/TestProject/src/main/java/sample/reflect-config.json -H:+ReportExceptionStackTraces

我还打开了堆栈跟踪异常报告。

现在,当我尝试编译为本机映像时,出现以下错误与本机库的使用有关:

Warning: System method java.lang.System.loadLibrary invoked at com.sun.glass.utils.NativeLibLoader.loadLibraryInternal(NativeLibLoader.java:163)
Warning: System method java.lang.System.loadLibrary invoked at com.sun.glass.utils.NativeLibLoader.loadLibraryInternal(NativeLibLoader.java:177)
Warning: Aborting stand-alone …
Run Code Online (Sandbox Code Playgroud)

java linux javafx maven graalvm

5
推荐指数
1
解决办法
2566
查看次数

标签 统计

graalvm ×1

java ×1

javafx ×1

linux ×1

maven ×1