我有一个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>
最初,我收到一条错误消息,指出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
我还打开了堆栈跟踪异常报告。
现在,当我尝试编译为本机映像时,出现以下与本机库的使用有关的错误:
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)
如何配置本机库的使用?在本机图像编译器工具中,没有任何选择,也没有我能在任何地方找到的任何提及。
我设法使用Native Image工具编译了其他项目,这意味着此问题与JavaFX有关。
答案 0 :(得分:2)
这种方式不起作用。为此,您将必须使用Gluons client-maven-plugin https://github.com/gluonhq/client-maven-plugin。它提供了经过编译的Java和JavaFX库的特殊版本来完成此工作。请严格按照说明进行操作。然后它将起作用。我会定期使用它。