I am trying to create a GraalVM compiled native executable connecting to kafka using org.springframework.kafka:spring-kafka. In plain java everything works fine. After compiling into native executable it fails to start throwing:
Caused by: org.apache.kafka.common.KafkaException: org.apache.kafka.common.KafkaException:
Could not find a public no-argument constructor for
org.apache.kafka.common.security.oauthbearer.internals.OAuthBearerSaslClientCallbackHandler
I've tried reflect-config.json as well as graalvm-reachability-metadata. Both to no avail. I couldn't find any working instruction via google, hence this post. I am using spring-boot 3.1.3.
Use GraalVM's native image agent:
java -agentlib:native-image-agent=config-merge-dir=PATH_TO_YOUR_SPRING_BOOT_PROJECT\src\main\resources\META-INF\native-image -jar PATH_TO_YOUR_SPRING_BOOT_PROJECT\target\NAME_OF_FAT_JAR.jar
It will produce reachability files in your project's resources folder. Then build your project using org.graalvm.buildtools:native-maven-plugin. The plugin will automatically pick up the files produced by the agent if you save them in resources\META-INF. If you still get missing classes, resources etc. during the execution - repeat the run. It will merge newly found information with previously created files. Very rudimentary documentation can be found here: https://www.graalvm.org/22.0/reference-manual/native-image/Agent/