quarkus: Native image creation fails with java.lang.NoClassDefFoundError: com/sun/jna/LastErrorException
Using the “quarkus-jdbc-postgresql” extension fails with the below error. Changing the database to “quarkus-jdbc-mariadb” fixes the problem. So it seems clearly to be related only to the postgresql extension.
[INFO] [io.quarkus.deployment.pkg.steps.NativeImageBuildStep] /home/developer/.sdkman/candidates/java/19.2.1-grl/jre/bin/native-image -J-DCoordinatorEnvironmentBean.transactionStatusManagerEnable=false -J-Dsun.nio.ch.maxUpdateArraySize=100 -J-Djava.util.logging.manager=org.jboss.logmanager.LogManager -J-Dvertx.logger-delegate-factory-class-name=io.quarkus.vertx.core.runtime.VertxLogDelegateFactory -J-Dvertx.disableDnsResolver=true -J-Dio.netty.leakDetection.level=DISABLED -J-Dio.netty.allocator.maxOrder=1 --report-unsupported-elements-at-runtime --initialize-at-build-time= -H:InitialCollectionPolicy=com.oracle.svm.core.genscavenge.CollectionPolicy$BySpaceAndTime -jar cqrs4j-quarkus-example-query-1.0-SNAPSHOT-runner.jar -J-Djava.util.concurrent.ForkJoinPool.common.parallelism=1 -H:FallbackThreshold=0 -H:+ReportExceptionStackTraces -H:-AddAllCharsets -H:EnableURLProtocols=http,https --enable-all-security-services -H:NativeLinkerOption=-no-pie -H:+JNI --no-server -H:-UseServiceLoaderFeature -H:+StackTrace cqrs4j-quarkus-example-query-1.0-SNAPSHOT-runner
[cqrs4j-quarkus-example-query-1.0-SNAPSHOT-runner:5066] classlist: 20,928.90 ms
[cqrs4j-quarkus-example-query-1.0-SNAPSHOT-runner:5066] setup: 2,172.90 ms
Fatal error: java.lang.NoClassDefFoundError
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at java.util.concurrent.ForkJoinTask.getThrowableException(ForkJoinTask.java:598)
at java.util.concurrent.ForkJoinTask.get(ForkJoinTask.java:1005)
at com.oracle.svm.hosted.NativeImageGenerator.run(NativeImageGenerator.java:461)
at com.oracle.svm.hosted.NativeImageGeneratorRunner.buildImage(NativeImageGeneratorRunner.java:310)
at com.oracle.svm.hosted.NativeImageGeneratorRunner.build(NativeImageGeneratorRunner.java:448)
at com.oracle.svm.hosted.NativeImageGeneratorRunner.main(NativeImageGeneratorRunner.java:113)
Caused by: java.lang.NoClassDefFoundError: com/sun/jna/LastErrorException
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Class.java:2701)
at java.lang.Class.getDeclaredMethods(Class.java:1975)
at com.oracle.svm.hosted.substitute.AnnotationSubstitutionProcessor.handleDeletedClass(AnnotationSubstitutionProcessor.java:437)
at com.oracle.svm.hosted.substitute.AnnotationSubstitutionProcessor.handleClass(AnnotationSubstitutionProcessor.java:270)
at com.oracle.svm.hosted.substitute.AnnotationSubstitutionProcessor.init(AnnotationSubstitutionProcessor.java:230)
at com.oracle.svm.hosted.NativeImageGenerator.createDeclarativeSubstitutionProcessor(NativeImageGenerator.java:875)
at com.oracle.svm.hosted.NativeImageGenerator.setupNativeImage(NativeImageGenerator.java:824)
at com.oracle.svm.hosted.NativeImageGenerator.doRun(NativeImageGenerator.java:524)
at com.oracle.svm.hosted.NativeImageGenerator.lambda$run$0(NativeImageGenerator.java:444)
at java.util.concurrent.ForkJoinTask$AdaptedRunnableAction.exec(ForkJoinTask.java:1386)
at java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:289)
at java.util.concurrent.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1056)
at java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1692)
at java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:157)
Error: Image build request failed with exit status 1
Expected behavior Native image creation should work with “quarkus-jdbc-postgresql” as it does with “quarkus-jdbc-mariadb”.
Actual behavior Native image creation fails with “–report-unsupported-elements-at-runtime” and also without this parameter for “quarkus-jdbc-postgresql”. Same project setup works fine with “quarkus-jdbc-mariadb”.
To Reproduce Steps to reproduce the behavior:
- Checkout project ddd-cqrs-4-java-example
- Change two files in quarkus module to use “postgres” instead of mariadb: “pom.xml” and “src/main/resources/application.properties” (See lines commented out)
- Follow the instructions in README.md: “Prerequisites” + “Getting started”
- Executing “./mvnw verify -Pnative -DskipTests” in module query will fail with above error
Environment (please complete the following information):
- VMware image with Ubuntu Bionic (Kernel 4.15.0-72-generic, x86_64, 8 GB memory)
- openjdk version “1.8.0_232”
- OpenJDK Runtime Environment (build 1.8.0_232-20191008104205.buildslave.jdk8u-src-tar–b07)
- OpenJDK 64-Bit GraalVM CE 19.2.1 (build 25.232-b07-jvmci-19.2-b03, mixed mode)
- Quarkus 1.0.1.Final
Additional context There was a similar issue #796, but I do not use the “shamrock-maven-plugin” as mentioned in that old issue.
About this issue
- Original URL
- State: open
- Created 5 years ago
- Reactions: 1
- Comments: 17 (11 by maintainers)
As another workaround, native-image configuration
<reportErrorsAtRuntime>true</reportErrorsAtRuntime>works for me (MacOs 10.13.6, GraalVM 20.0.0 CE, Quarkus 1.3.0.Final), when I add the following dependencies (version managed by quarkus bom):I could reproduce this issue and I had to add this additional dependency to make it work:
Note that this dependency is not under quarkus bom, so I had to manually set the version.
An explanation of why this is happening can be found in https://github.com/oracle/graal/issues/1725
As explained there:
So manually adding the dependencies might work around the issue and might be acceptable for development purposes but production code should not use
--report-unsupported-elements-at-runtime.