0

** I have updated below **

Here is my info. | Java version | 17.0.7+8-LTS | | Vendor version | Oracle GraalVM 17.0.7+8.1 | Relevant Pom changes for native image:

   <dependency>
        <groupId>org.graalvm.buildtools</groupId>
        <artifactId>graalvm-reachability-metadata</artifactId>
        <version>${native.maven.plugin.version}</version>
        <classifier>repository</classifier>
        <type>zip</type>
    </dependency>
</dependencies>


<profiles>
    <profile>
        <id>native</id>
        <build>
            <plugins>
                <plugin>
                    <groupId>org.graalvm.buildtools</groupId>
                    <artifactId>native-maven-plugin</artifactId>
                    <version>${native.maven.plugin.version}</version>
                    <extensions>true</extensions>
                    <executions>
                        <execution>
                            <id>build-native</id>
                            <goals>
                                <goal>compile-no-fork</goal>
                            </goals>
                            <phase>package</phase>
                        </execution>
                    </executions>
                    <configuration>
                        <metadataRepository>
                            <enabled>true</enabled>
                        </metadataRepository>
                        <skipNativeTests>true</skipNativeTests>
                        <imageName>${imageName}</imageName>
                        <fallback>false</fallback>
                        <verbose>true</verbose>
                        <agent>
                            <defaultMode>Standard</defaultMode>
                            <enabled>true</enabled>
                            <modes>
                                <direct>config-output-dir=${project.build.directory}/native/agent-output</direct>
                            </modes>
                            <trackReflectionMetadata>true</trackReflectionMetadata>
                        </agent>
                    </configuration>
                </plugin>
                <plugin>
                    <groupId>org.codehaus.mojo</groupId>
                    <artifactId>exec-maven-plugin</artifactId>
                    <version>3.0.0</version>
                    <executions>
                        <execution>
                            <id>java-agent</id>
                            <goals>
                                <goal>exec</goal>
                            </goals>
                            <configuration>
                                <executable>java</executable>
                                <workingDirectory>${project.build.directory}</workingDirectory>
                                <arguments>
                                    <argument>-classpath</argument>
                                    <classpath/>
                                    <argument>${mainClass}</argument>
                                </arguments>
                            </configuration>
                        </execution>
                    </executions>
                </plugin>
                <plugin>
                    <groupId>org.codehaus.mojo</groupId>
                    <artifactId>exec-maven-plugin</artifactId>
                    <version>3.0.0</version>
                    <executions>
                        <execution>
                            <id>java-agent</id>
                            <goals>
                                <goal>exec</goal>
                            </goals>
                            <configuration>
                                <executable>java</executable>
                                <workingDirectory>${project.build.directory}</workingDirectory>
                                <arguments>
                                    <argument>-classpath</argument>
                                    <classpath/>
                                    <argument>${mainClass}</argument>
                                </arguments>
                            </configuration>
                        </execution>
                    </executions>
                </plugin>
            </plugins>
        </build>
    </profile>
</profiles>


<build>
    <plugins>
        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>exec-maven-plugin</artifactId>
            <version>3.0.0</version>
            <executions>
                <execution>
                    <id>java</id>
                    <goals>
                        <goal>java</goal>
                    </goals>
                    <configuration>
                        <mainClass>${mainClass}</mainClass>
                    </configuration>
                </execution>
            </executions>
        </plugin>
        <plugin>
            <groupId>org.graalvm.buildtools</groupId>
            <artifactId>native-maven-plugin</artifactId>
            <configuration>
                <skipNativeTests>true</skipNativeTests>
            </configuration>
        </plugin>

I would run mvn -Pnative -DskipTests native:compile This produces these folders in target with the json files, but they all these packages such as ch.qos.logbacj, com.google.protobuf, io.netty, etc which i don't direclty use in my app: classes/META-INF/native-image, graalvm-reachability-metadata, spring-aot. I tried taking the spring-aot META-INF json files and place it into the app's classpath. I would run again and the logs would indicate it transfers the classpath folders into target classes folder and applys all the json files in the target/classes/META-INF

At the end, i get a lot of warning on all these obscure classes and this error at end:

 C compiler: cl.exe (microsoft, x64, 19.36.32537)
 Garbage collector: Serial GC (max heap size: 80% of RAM)
 6 user-specific feature(s)
 - com.google.api.gax.grpc.nativeimage.GrpcNettyFeature
 - com.google.api.gax.grpc.nativeimage.ProtobufMessageFeature
 - com.google.api.gax.nativeimage.GoogleJsonClientFeature
 - com.google.api.gax.nativeimage.OpenCensusFeature
 - com.oracle.svm.thirdparty.gson.GsonFeature
 - org.springframework.aot.nativex.feature.PreComputeFieldFeature
Warning: Unknown attribute(s) [//note] in resource and resource bundle descriptor object
Aug 17, 2023 11:03:20 AM com.google.api.gax.nativeimage.NativeImageUtils registerClassForReflection
WARNING: Failed to find io.grpc.netty.shaded.io.netty.channel.ProtocolNegotiators on the classpath for reflection.
WARNING: Resource scanning is taking a long time. This can be caused by class-path or module-path entries that point to large directory structures. Please make sure class-/module-path entries are easily accessible to native-image
Total scanned entries: 37590, current entry: file:///C:/graalvm-jdk-17.0.7+8.1/lib/svm/builder/svm.jar
Total scanned entries: 49314, current entry: file:///C:/Users/myself/.m2/repository/io/netty/netty-handler/4.1.94.Final/netty-handler-4.1.94.Final.jar
Total scanned entries: 62667, current entry: file:///C:/Users/myself/.m2/repository/com/fasterxml/jackson/core/jackson-databind/2.13.4.1/jackson-databind-2.13.4.1.jar
Total scanned entries: 74685, current entry: file:///C:/Users/myself/.m2/repository/org/springframework/spring-aop/6.0.10/spring-aop-6.0.10.jar
Total scanned entries: 88132, current entry: file:///C:/Users/myself/.m2/repository/org/springframework/data/spring-data-commons/3.0.7/spring-data-commons-3.0.7.jar
Total scanned entries: 101563, current entry: file:///C:/Users/myself/.m2/repository/io/opencensus/opencensus-api/0.31.1/opencensus-api-0.31.1.jar 
    

Stack Trace

java.lang.NullPointerException: Cannot invoke "java.util.Set.iterator()" because "triggers" is null

That is a section of some of the errors. There are a lot of these warning errors. I do have an xx.json files generated in native/agent-output/main. How can I resolve these and get the image generated?

** UPDATE ** August 21st 2023 **** Based on looking into the error, I found that when i comment out the google dependency, the native build completes successfully but my app doesn't run.

I commented out this dependency:

com.google.cloud spring-cloud-gcp-dependencies and gcp secret manager dependency.

Now i get this error: Segmentation fault: 11 (using mac). I am currently trying to use a older version of xCode 12.5.1

chocokoala
  • 191
  • 4
  • 15

1 Answers1

0

No need to define $mainClass or those many parameters in your pom, they are all managed by spring boot. Also you do not need to run agent for spring boot dependencies meaning jackson libraries.

Check here for clean starting pom then build from there.

For native build the command is mvn -Pnative native:compile this will generate the executable file in the "target" folder.

Here is a good swagger example which works with json and all.

ozkanpakdil
  • 3,199
  • 31
  • 48
  • Hi. I took your suggestion and only used the base settings of plugins in build section. org.graalvm.buildtools native-maven-plugin I had been using mvn -Pnative -DskipTests native:compile. The results are the same. I had been trying this method: java -Dspring.aot.enabled=true -agentlib:native-image-agent=config-output-dir=./config -jar target/ but -Dspring.aot.enabled=true , does not run the application I am going to update my above question – chocokoala Aug 18 '23 at 13:18
  • how do i ignore jackson libraries? – chocokoala Aug 18 '23 at 13:59
  • Also @ozkanpakdil, your swagger example doesn't work. I tried on windows and mac INFO] ------------------------------------------------------------------------ [ERROR] Failed to execute goal org.graalvm.buildtools:native-maven-plugin:0.9.20:compile (default-cli) on project demo: Execution default-cli of goal org.graalvm.buildtools:native-maven-plugin:0.9.20:compile failed: Version to check 'native-image 17.0.8 2023-07-18 [ERROR] GraalVM Runtime Environment Oracle GraalVM 17.0.8+9.1 (build 17.0.8+9-LTS-jvmci-23.0-b14) – chocokoala Aug 18 '23 at 15:55
  • @chocokoala hello I just upgraded and see the swagger working in graalvm native binary. please update my code and test again. the command is the same and everything works, and feel free to update me if you see any problems. – ozkanpakdil Aug 18 '23 at 22:21
  • Hi @ozkanpakdil, now the build completes but cannot run demo app on the mac. ./target/demo Segmentation fault: 11 – chocokoala Aug 21 '23 at 13:29
  • I do not have a mac but good news I see it working in linux :) @chocokoala – ozkanpakdil Aug 21 '23 at 16:01