I'm new to Quarkus and trying to build a native image using "mvn package -Pnative". I received the error "Error: Classes that should be initialized at run time got initialized during image building:" so in the pom.xml I added an additional build arg --initialize-at-run-time with a \, separated list for these classes. When I run the mvn command again, all of these classes still say that they need to be initialized at run time.
I tried to build the native image, got the Error that several classes need to be initialized at run time, and so tried to build again after adding --initialize-at-run-time in the additional build args with the specified classes. I expected that if a class is added to --initialize-at-run-time, it should not give me the error that the same class needs to be initialized at run time when running the mvn command, and the build should succeed.
Process and details:
- I entered into the Intellij terminal : "mvn package -Pnative"
- After finishing tests, there is the following INFO line :
[INFO] [io.quarkus.deployment.pkg.steps.NativeImageBuildRunner] /Library/Java/JavaVirtualMachines/graalvm-ce-java11-22.3.0/Contents/Home/bin/native-image -J-Dsun.nio.ch.maxUpdateArraySize=100 -J-Djava.util.logging.manager=org.jboss.logmanager.LogManager -J-Dlogging.initial-configurator.min-level=500 -J-Dio.netty.leakDetection.level=DISABLED -J-Dio.netty.allocator.maxOrder=3 -J-Dvertx.logger-delegate-factory-class-name=io.quarkus.vertx.core.runtime.VertxLogDelegateFactory -J-Dvertx.disableDnsResolver=true -J-Duser.language=en -J-Duser.country=US -J-Dfile.encoding=UTF-8 --features=io.quarkus.runner.Feature,io.quarkus.runtime.graal.ResourcesFeature,io.quarkus.runtime.graal.DisableLoggingFeature -J--add-exports=java.security.jgss/sun.security.krb5=ALL-UNNAMED -J--add-opens=java.base/java.text=ALL-UNNAMED -J--add-opens=java.base/java.io=ALL-UNNAMED -J--add-opens=java.base/java.lang.invoke=ALL-UNNAMED -J--add-opens=java.base/java.util=ALL-UNNAMED -H:+CollectImageBuildStatistics -H:ImageBuildStatisticsFile=[PROJECT-NAME]-1.0.0-SNAPSHOT-runner-timing-stats.json -H:BuildOutputJSONFile=[PROJECT-NAME]-1.0.0-SNAPSHOT-runner-build-output-stats.json --initialize-at-run-time=io.netty.buffer.UnpooledDirectByteBuf,io.netty.handler.ssl.ReferenceCountedOpenSslContext,io.netty.buffer.UnpooledHeapByteBuf,io.netty.buffer.ByteBufUtil,io.netty.buffer.AbstractReferenceCountedByteBuf,io.netty.channel.kqueue.KQueue,io.netty.buffer.UnpooledByteBufAllocator\$InstrumentedUnpooledUnsafeDirectByteBuf,io.netty.handler.ssl.OpenSslContext,io.netty.util.concurrent.ScheduledFutureTask,io.netty.buffer.AbstractPooledDerivedByteBuf,io.netty.buffer.PooledByteBufAllocator,io.netty.handler.ssl.ReferenceCountedOpenSslClientContext,io.netty.buffer.UnpooledUnsafeDirectByteBuf,io.netty.channel.DefaultFileRegion,io.netty.handler.ssl.OpenSslClientContext,io.netty.util.concurrent.GlobalEventExecutor,io.netty.channel.epoll.Epoll,io.netty.util.AbstractReferenceCounted,io.netty.buffer.ByteBufAllocator,io.netty.buffer.PooledSlicedByteBuf,io.netty.buffer.PooledByteBuf,io.netty.buffer.PooledUnsafeDirectByteBuf -H:InitialCollectionPolicy=com.oracle.svm.core.genscavenge.CollectionPolicy\$BySpaceAndTime -H:+AllowFoldMethods -J-Djava.awt.headless=true --no-fallback --link-at-build-time -H:+ReportExceptionStackTraces -H:-AddAllCharsets --enable-url-protocols=http,https -H:-UseServiceLoaderFeature -H:+StackTrace -J--add-exports=org.graalvm.sdk/org.graalvm.nativeimage.impl=ALL-UNNAMED -J--add-exports=org.graalvm.nativeimage.builder/com.oracle.svm.core.jdk=ALL-UNNAMED [PROJECT-NAME]-1.0.0-SNAPSHOT-runner -jar [PROJECT-NAME]-1.0.0-SNAPSHOT-runner.jar
it runs through 1/7 initializing and 2/7 performing analysis until hitting errors like:
Error: Classes that should be initialized at run time got initialized during image building: io.netty.buffer.AbstractReferenceCountedByteBuf the class was requested to be initialized at run time ....... in 'file:///path/to/project/target/[PROJECT-NAME]-1.0.0-SNAPSHOT-native-image-source-jar/lib/io.netty.netty-buffer-4.1.79.Final.jar'
- the end of the errors has the following line that contains all of the same classes that I had specified:
To see how the classes got initialized, use --trace-class-initialization=io.netty.channel.kqueue.KQueue,io.netty.handler.ssl.OpenSslContext,io.netty.buffer.PooledUnsafeDirectByteBuf,io.netty.buffer.UnpooledHeapByteBuf,io.netty.channel.DefaultFileRegion,io.netty.buffer.PooledSlicedByteBuf,io.netty.buffer.PooledByteBuf,io.netty.handler.ssl.ReferenceCountedOpenSslClientContext,io.netty.util.AbstractReferenceCounted,io.netty.handler.ssl.OpenSslClientContext,io.netty.buffer.AbstractPooledDerivedByteBuf,io.netty.buffer.UnpooledByteBufAllocator$InstrumentedUnpooledUnsafeDirectByteBuf,io.netty.buffer.ByteBufUtil,io.netty.channel.epoll.Epoll,io.netty.util.concurrent.GlobalEventExecutor,io.netty.buffer.UnpooledUnsafeDirectByteBuf,io.netty.buffer.UnpooledDirectByteBuf,io.netty.buffer.AbstractReferenceCountedByteBuf,io.netty.handler.ssl.ReferenceCountedOpenSslContext,io.netty.buffer.PooledByteBufAllocator,io.netty.buffer.ByteBufAllocator,io.netty.util.concurrent.ScheduledFutureTask
- the end of the errors has the following line that contains all of the same classes that I had specified:
the different causes after adding trace-class-initialization to the pom were:
com.azure.cosmos.implementation.directconnectivity.rntbd.RntbdLoopNativeDetector
reactor.netty.http.client.HttpClientSecure
com.azure.cosmos.implementation.directconnectivity.rntbd.RntbdServiceEndpoint$RntbdEndpointMonitoringProvider
reactor.netty.resources.DefaultLoopNativeDetector
io.netty.handler.ssl.OpenSsl
I also tried adding these to the --initialize-at-run-time but that did not resolve it
the message after build failure:
[ERROR] Failed to execute goal io.quarkus.platform:quarkus-maven-plugin:2.13.1.Final:build on project: Failed to build quarkus application: io.quarkus.builder.BuildException: Build failure: Build failed due to errors
I'm unable to provide the project as it contains sensitive and internal info but I added the following to the native profile in my pom.xml to try and resolve the error:
<quarkus.native.additional-build-args>--initialize-at-run-time=io.netty.buffer.UnpooledDirectByteBuf\,io.netty.handler.ssl.ReferenceCountedOpenSslContext\,io.netty.buffer.UnpooledHeapByteBuf\,io.netty.buffer.ByteBufUtil\,io.netty.buffer.AbstractReferenceCountedByteBuf\,io.netty.channel.kqueue.KQueue\,io.netty.buffer.UnpooledByteBufAllocator$InstrumentedUnpooledUnsafeDirectByteBuf\,io.netty.handler.ssl.OpenSslContext\,io.netty.util.concurrent.ScheduledFutureTask\,io.netty.buffer.AbstractPooledDerivedByteBuf\,io.netty.buffer.PooledByteBufAllocator\,io.netty.handler.ssl.ReferenceCountedOpenSslClientContext\,io.netty.buffer.UnpooledUnsafeDirectByteBuf\,io.netty.channel.DefaultFileRegion\,io.netty.handler.ssl.OpenSslClientContext\,io.netty.util.concurrent.GlobalEventExecutor\,io.netty.channel.epoll.Epoll\,io.netty.util.AbstractReferenceCounted\,io.netty.buffer.ByteBufAllocator\,io.netty.buffer.PooledSlicedByteBuf\,io.netty.buffer.PooledByteBuf\,io.netty.buffer.PooledUnsafeDirectByteBuf</quarkus.native.additional-build-args>
I'm running on a Mac with M1/aarch64, Monterey 12.6. java -version output is:
openjdk version "11.0.17" 2022-10-18 OpenJDK Runtime Environment GraalVM CE 22.3.0 (build 11.0.17+8-jvmci-22.3-b08) OpenJDK 64-Bit Server VM GraalVM CE 22.3.0 (build 11.0.17+8-jvmci-22.3-b08, mixed mode)
and echo $JAVA_HOME is /Library/Java/JavaVirtualMachines/graalvm-ce-java11-22.3.0/Contents/Home". GraalVM is version 22.3.0, Quarkus-maven-plugin is version 2.13.1.Final, and I use maven 3.8.6.