如何使用GraalVM和JavaFX在Maven中编译本机映像? [英] How to use GraalVM with JavaFX to compile a native image in Maven?

查看:502
本文介绍了如何使用GraalVM和JavaFX在Maven中编译本机映像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have a JavaFX project, and would like to compile it into a Linux binary using the GraalVM Java virtual machine and the associated Native-Image tool. I am using GraalVM Java 11 Version 20.1.0, and the Native Image Maven plugin, that is added through Maven, to achieve this.

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

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

Originally, I got an error stating Warning: Aborting stand-alone image build due to reflection use without configuration. I used the Native Image tracing agent to generate config files for reflection, which I pass into the compiler plugin like this: -H:ReflectionConfigurationFiles=/home/user/Documents/Projects/TestProject/src/main/java/sample/reflect-config.json -H:+ReportExceptionStackTraces

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

I also have stack trace exception reporting turned on.

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

Now, when I attempt to compile to a native image, I get the following error to do with the usage of native libraries:

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 image build due to loading native libraries without configuration.
com.oracle.svm.hosted.FallbackFeature$FallbackImageRequest: System method java.lang.System.loadLibrary invoked at com.sun.glass.utils.NativeLibLoader.loadLibraryInternal(NativeLibLoader.java:163)
System method java.lang.System.loadLibrary invoked at com.sun.glass.utils.NativeLibLoader.loadLibraryInternal(NativeLibLoader.java:177)
Aborting stand-alone image build due to loading native libraries without configuration.
    at com.oracle.svm.hosted.FallbackFeature.afterAnalysis(FallbackFeature.java:293)
    at com.oracle.svm.hosted.NativeImageGenerator.lambda$runPointsToAnalysis$9(NativeImageGenerator.java:741)
    at com.oracle.svm.hosted.FeatureHandler.forEachFeature(FeatureHandler.java:70)
    at com.oracle.svm.hosted.NativeImageGenerator.runPointsToAnalysis(NativeImageGenerator.java:741)
    at com.oracle.svm.hosted.NativeImageGenerator.doRun(NativeImageGenerator.java:538)
    at com.oracle.svm.hosted.NativeImageGenerator.lambda$run$0(NativeImageGenerator.java:451)
    at java.base/java.util.concurrent.ForkJoinTask$AdaptedRunnableAction.exec(ForkJoinTask.java:1407)
    at java.base/java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:290)
    at java.base/java.util.concurrent.ForkJoinPool$WorkQueue.topLevelExec(ForkJoinPool.java:1020)
    at java.base/java.util.concurrent.ForkJoinPool.scan(ForkJoinPool.java:1656)
    at java.base/java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1594)
    at java.base/java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:177)

如何配置本机库的使用?在本机图像编译器工具中没有此选项,也没有我可以在任何地方找到的任何提及.

How can I configure the use of native libraries? There is no option for this within the Native Image compiler tool, nor any mention of it that I can find anywhere.

我设法使用Native Image工具编译了其他项目,这意味着此问题与JavaFX有关.

I have managed to compile other projects with the Native Image tool, which means that this problem is JavaFX related.

推荐答案

这种方式不起作用.您将必须使用Gluons client-maven-plugin https://github.com/gluonhq/client -maven-plugin .它提供了经过编译的Java和JavaFX库的特殊版本来完成此工作.请严格按照说明进行操作.然后它将起作用.我会定期使用它.

This does not work that way. You will have to use Gluons client-maven-plugin https://github.com/gluonhq/client-maven-plugin for this purpose. It provides a special version of compiled Java and JavaFX libraries to make this work. Follow the instructions closely. Then it will work. I am using it on a regular basis.

这篇关于如何使用GraalVM和JavaFX在Maven中编译本机映像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆