native build failure: classes specified in --initialize-at-run-time still say that they are requested to be initialized at run time - quarkus

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

Related

How to set up apache ranger on apple macbook pro m1

I'm trying to set up apache ranger for work using this https://github.com/apache/ranger/tree/master/dev-support/ranger-docker
however by running
mvn clean package -DskipTests
I'm getting the following error: [ERROR] Failed to execute goal org.apache.maven.plugins:maven-war-plugin:2.6:exploded (prepare) on project security-admin-web: Execution prepare of goal org.apache.maven.plugins:maven-war-plugin:2.6:exploded failed: Unable to load the mojo 'exploded' in the plugin 'org.apache.maven.plugins:maven-war-plugin:2.6' due to an API incompatibility: org.codehaus.plexus.component.repository.exception.ComponentLookupException: null The entire error can be seen in this picture:
[1]
and as an alternative provided in the github, when I run:
docker-compose -f docker-compose.ranger-base.yml -f docker-compose.ranger-build.yml up
I get the error:
ranger-build | The JAVA_HOME environment variable is not defined correctly
ranger-build | This environment variable is needed to run this program
ranger-build | NB: JAVA_HOME should point to a JDK not a JRE
ranger-build | mv: cannot stat 'target/ranger-*': No such file or directory
ranger-build exited with code 1
I have also tried following https://medium.com/swlh/hands-on-apache-ranger-docker-poc-with-hadoop-hdfs-hive-presto-814344a03a17
however it gets stuck in the ranger-admin container and localhost:6080 doesn't work.
[1]: https://i.stack.imgur.com/57ubI.jpg
I was able to solve this by downgrading my maven to 3.6.3 as I was having incompatibility issues, although this particular issue was resolved by adding maven war 2.6 plug in in pom.xml but then more incompatibility issues arose so i had to uninstall and reinstall a completely different maven version and that fixed all the issues.

Grails v3.0.17 Project Runnig fine in linux but unable to build in mac os

I have a grails project version 3 and it is running absolutly fine on intellij ide v 2018.3.6 in linux os but same project when i try to run on mac os its build is getting failed.
Grails version 3.0.17 and
Intellij Idea version 2018.3.6 and Groovy Version: 2.4.5
gradle-wrapper.properties of my project
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-2.3-all.zip
whenever i try to build this project using ./gradlew build this is the error i am getting
:compileGroovy
/Users/tom/ptoject/code/grailsTestProject/build/tmp/compileGroovy/groovy-java-stubs/com/example/util/Test.java:12: error: cannot access Test
extends com.example.util.vo.Test implements
^
bad source file: /Users/tom/ptoject/code/grailsTestProject/build/tmp/compileGroovy/groovy-java-stubs/com/example/util/Test.java
file does not contain class com.examle.util.Test
Please remove or make sure it appears in the correct subdirectory of the sourcepath.
startup failed:
Compilation failed; see the compiler error output for details.
1 error
:compileGroovy FAILED
This extends com.example.util.vo.Test class is a common class for multiple projects so i declared this in a separate java project and using it as a jar on different projects
Now i think this jar is creating issue in mac

Build the project using gradle

I have so far used maven to build the java code.
I was trying to build this project which is using gradle: https://github.com/opendistro-for-elasticsearch/anomaly-detection
I followed the below steps and it is failing continuously in build.
After cloning the code,
Step 1: As per the steps mentioned in the link, I installed java first and set the Java home and path like below
yum install java-1.8.0-openjdk
export JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk
export PATH=$JAVA_HOME/bin:$PATH
Step 2 : I tried to build the project using gradlew like below and end up with the error,
anomaly-detection]# ./gradlew
Starting a Gradle Daemon, 1 incompatible Daemon could not be reused, use --status for details
FAILURE: Build failed with an exception.
* Where:
Build file '/host/eclipse_back/opendistro/anomaly-detection/build.gradle' line: 55
* What went wrong:
A problem occurred evaluating root project 'opendistro-anomaly-detection'.
> Failed to apply plugin [id 'elasticsearch.esplugin']
> Could not create plugin of type 'PluginBuildPlugin'.
> Could not generate a decorated class for type PluginBuildPlugin.
> org/elasticsearch/gradle/plugin/PluginPropertiesExtension has been compiled by a more recent version of the Java Runtime (class file version 54.0), this version of the Java Runtime only recognizes class file versions up to 52.0
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
BUILD FAILED in 8s
Why it's failing? Any help is appreciated!
Thanks,
Harry
You need to setup your build environment for gradle to use a more recent java version. You can set the java version with the gradle property org.gradle.java.home:
org.gradle.java.home=<path to JDK home>
I think the problem is that you use Java 8 and in the README they want to use Java 14.
To build from command line set JAVA_HOME to point to a JDK 14 before running ./gradlew
Then it should be possible to build and test the project with the following command:
./gradlew build
EDIT:
Can you check your configuration of your IDE. Did the Gradle JVM use the correct Java version? If you are using Intellik you can check it following this post:

JenkinsX - Build fail due to Java Heap space

I am working on creating CI/CD pipeline for Spring Boot application on GKE using JenkinsX. As soon as I push the code to the master branch, build gets triggered but the build fails due to insufficient Java heap space.
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-war-plugin:3.2.2:war (default-war) on project location-finder-api: Error assembling WAR: Problem creating war: Execution exception: Java heap space -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.apache.maven.plugins:maven-war-plugin:3.2.2:war (default-war) on project location-finder-api: Error assembling WAR: Problem creating war: Execution exception
Caused by: java.lang.OutOfMemoryError: Java heap space
at org.codehaus.plexus.archiver.zip.ByteArrayOutputStream.needNewBuffer (ByteArrayOutputStream.java:153)
at org.codehaus.plexus.archiver.zip.ByteArrayOutputStream.write (ByteArrayOutputStream.java:192)
To resolve I tried to set the JVM argument in the Docekrfile as
CMD ["java", "-Xmx1024m","-jar", "app.jar"]
But it did not work. This is what I see when the build starts
+ mvn -e clean deploy -Pprod
Picked up _JAVA_OPTIONS: -XX:+UnlockExperimentalVMOptions -XX:+UseCGroupMemoryLimitForHeap -Dsun.zip.disableMemoryMapping=true -XX:+UseParallelGC -XX:MinHeapFreeRatio=5 -XX:MaxHeapFreeRatio=10 -XX:GCTimeRatio=4 -XX:AdaptiveSizePolicyWeight=90 -Xms10m -Xmx192m
OpenJDK 64-Bit Server VM warning: If the number of processors is expected to increase from one, then you should configure the number of parallel GC threads appropriately using -XX:ParallelGCThreads=N
Is there any way that I can set this heap option on my own?
it looks like maven is running out of memory so you need more memory in your build pod (not the Dockerfile for your app).
as a quick test you can edit the pod template inside the Jenkins UI: jx console then Manage Jenkins -> Configure System then find the jenkins-maven pod template in the UI and edit the _JAVA_OPTIONS environment variable from this value: https://github.com/jenkins-x/jenkins-x-platform/blob/master/jenkins-x-platform/values.yaml#L907 - try change -Xmx512m to something bigger like -Xmx912m
Once you've found a value that works for your projects you can make the change permanent of restarts of Jenkins by adding this to your myvalues.yaml - something like this...
# myvalues.yaml
jenkins:
Agent:
PodTemplates:
Maven:
Name: maven
Label: jenkins-maven
EnvVars:
_JAVA_OPTIONS: '-XX:+UnlockExperimentalVMOptions -Dsun.zip.disableMemoryMapping=true -XX:+UseParallelGC -XX:MinHeapFreeRatio=5 -XX:MaxHeapFreeRatio=10 -XX:GCTimeRatio=4 -XX:AdaptiveSizePolicyWeight=90 -Xms10m -Xmx912m'
see the docs on creating/configuring builders

Grails - How to add Oracle jdbc jar to classpath without placing in /lib?

I am attempting to get my grails application running locally with tomcat, but without placing ojdbc6.jar in /lib. My grails application is deployed to Glassfish and works fine on the server (because the ojdbc6.jar is available there). As expected the error is:
Could not load JDBC driver class [oracle.jdbc.driver.OracleDriver]
(Failed) Approach #1
I first customized my GGTS run-configuration to include the VM arguments:
-cp :/somelocalpath/oracle-jdbc-drivers
However the error persisted.
(Failed) Approach #2
I'm currently looking to use the jvmArgs to point to a local version of the jar.
grails.tomcat.jvmArgs = ["-cp:/somelocalpath/oracle-jdbc-drivers/ojdbc6.jar"]
However a run-war results in:
| Error Server failed to start: tomcat exited prematurely with code '1' (error output: 'Unrecognized option: -cp:/apps/glassfish3/oracle-jdbc-drivers/ojdbc6.jar
Error: Could not create the Java Virtual Machine.
Error: A fatal exception has occurred. Program will exit.
')
I should clarify my main focus - I do not want the jar to be included in the final war.
Any help would be appreciated. Thanks!
From the documentation:
grails.war.resources lets you do any extra processing you want
before the WAR file is finally created.
In your case, you need to add something like that to your build config to exclude the Jar of the final WAR.
grails.war.resources = { stagingDir ->
delete(file:"${ stagingDir }/WEB-INF/lib/yourJarFile.jar")
}

Resources