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>
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.
I have managed to compile other projects with the Native Image tool, which means that this problem is JavaFX related.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With