Native-java(3)

本文涉及的产品
云数据库 RDS SQL Server,基础系列 2核4GB
RDS SQL Server Serverless,2-4RCU 50GB 3个月
推荐场景:
简介: Native-java(3)

springboot项目构建可执行文件

两种方式

  • (失败)springboot插件打包成jar,然后native-image构建jar包为可执行文件
  • (成功)spring官方插件,两个都需要
  • spring-boot-maven-plugin
  • native-maven-plugin

demo代码

package com.example.controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
/**
 * @author 伍六七
 * @date 2023/8/4 19:20
 */
@RestController
@RequestMapping("/")
public class DemoController {
    @GetMapping("/hello")
    public String hello(){
        return "hello";
    }
}
package com.example;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@SpringBootApplication
public class GraalvmSpringBootDemoApplication {
    public static void main(String[] args) {
        SpringApplication.run(GraalvmSpringBootDemoApplication.class, args);
    }
}

(失败)打包成jar+native-image构建可执行文件

该方法目前有问题

这里是issue

测试过程

pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.example</groupId>
    <artifactId>Graalvm-SpringBoot-Demo</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>Graalvm-SpringBoot-Demo</name>
    <description>Graalvm-SpringBoot-Demo</description>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>3.1.0</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <properties>
        <java.version>17</java.version>
        <maven.compiler.source>17</maven.compiler.source>
        <maven.compiler.target>17</maven.compiler.target>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <spring-boot.version>3.1.0</spring-boot.version>
        <main-class>com.example.GraalvmSpringBootDemoApplication</main-class>
    </properties>
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>
    <build>
        <!--包名-->
        <!--        <finalName>${project.artifactId}</finalName>-->
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <version>${spring-boot.version}</version>
                <!--替换为你的应用程序主类-->
                <configuration>
                    <mainClass>${main-class}</mainClass>
                    <excludes>
                        <exclude>
                            <groupId>org.projectlombok</groupId>
                            <artifactId>lombok</artifactId>
                        </exclude>
                    </excludes>
                </configuration>
                <executions>
                    <execution>
                        <id>repackage</id>
                        <goals>
                            <goal>repackage</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>

正常运行

maven打包成jar

先打包

mvn package

native-image构建可执行文件

在target目录下

native-image -jar .\Graalvm-SpringBoot-Demo-0.0.1-SNAPSHOT.jar --no-fallback

构建成功,但是执行时就失败了报错java.util.zip.ZipException: zip END header not found

(成功)native-maven-plugin

spring官方有打包的工具

官方文档:https://docs.spring.io/spring-boot/docs/current/reference/html/native-image.html#native-image.developing-your-first-application.buildpacks.maven

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.example</groupId>
    <artifactId>Graalvm-SpringBoot-Demo</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>Graalvm-SpringBoot-Demo</name>
    <description>Graalvm-SpringBoot-Demo</description>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>3.1.0</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <properties>
        <java.version>17</java.version>
        <maven.compiler.source>17</maven.compiler.source>
        <maven.compiler.target>17</maven.compiler.target>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <spring-boot.version>3.1.0</spring-boot.version>
        <main-class>com.example.GraalvmSpringBootDemoApplication</main-class>
    </properties>
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>
    <build>
        <plugins>
            <plugin>
                <groupId>org.graalvm.buildtools</groupId>
                <artifactId>native-maven-plugin</artifactId>
                <configuration>
                    <!-- imageName用于设置生成的二进制文件名称 -->
                    <imageName>${project.artifactId}</imageName>
                    <!-- mainClass用于指定main方法类路径 -->
                    <mainClass>${main-class}</mainClass>
                </configuration>
                <executions>
                    <execution>
                        <id>build-native</id>
                        <goals>
                            <goal>compile-no-fork</goal>
                        </goals>
                        <phase>package</phase>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <configuration>
                    <excludes>
                        <exclude>
                            <groupId>org.projectlombok</groupId>
                            <artifactId>lombok</artifactId>
                        </exclude>
                    </excludes>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>
mvn clean package -Pnative

可以看到执行了很多

下面就是转换为可执行文件了

成功

遇到的问题

spring项目

java.util.zip.ZipException: zip END header not found

官方回复

解决方法:

使用spring的打包插件

Please use to build the image.    mvn -Pnative native:compile

github相同问题:

https://github.com/oracle/graal/issues/3117

https://github.com/oracle/graal/issues/7034

场景重现

当时的命令

native-image -jar .\Graalvm-SpringBoot-Demo-0.0.1-SNAPSHOT.jar --no-fallback

构建完成,exe文件看起来ok,但是执行报错

运行报错

查看完整信息

native-image -jar .\Graalvm-SpringBoot-Demo-0.0.1-SNAPSHOT.jar --no-fallback --verbose
PS F:\study\code\myProject\Graalvm-SpringBoot-Demo\target> native-image -jar .\Graalvm-SpringBoot-Demo-0.0.1-SNAPSHOT.jar --no-fallback --verbose
Apply jar:file:///F:/develop/graalvm-jdk-17_windows-x64_bin/graalvm-jdk-17.0.8+9.1/lib/svm/library-support.jar!/META-INF/native-image/com.oracle.svm/thirdparty/native-image.properties
Apply jar:file:///F:/develop/graalvm-jdk-17_windows-x64_bin/graalvm-jdk-17.0.8+9.1/lib/svm/library-support.jar!/META-INF/native-image/com.oracle.svm/polyglot/native-image.properties
Executing [
'INCLUDE=C:\Program Files (x86)\Windows Kits\10\Include\10.0.22621.0\um;C:\Program Files (x86)\Windows Kits\10\Include\10.0.22621.0\ucrt;C:\Program Files (x86)\Windows Kits\10\Include\10.0.22621.0\shared;F:\develop\MicrosoftVisualStudio\VC\Tools\MSVC\14.37.32820\include;' \
'LIB=C:\Program Files (x86)\Windows Kits\10\Lib\10.0.22621.0\um\x64;C:\Program Files (x86)\Windows Kits\10\Lib\10.0.22621.0\ucrt\x64;F:\develop\MicrosoftVisualStudio\VC\Tools\MSVC\14.37.32820\lib\x64;' \
'Path=F:\develop\MicrosoftVisualStudio\VC\Tools\MSVC\14.37.32820\bin\Hostx64\x64;F:\develop\graalvm-jdk-17_windows-x64_bin\graalvm-jdk-17.0.8+9.1\bin;F:\develop\python39\Scripts;C:\Program Files\Common Files\Oracle\Java\javapath;C:\Program Files (x86)\Common Files\Intel\Shared Libraries\redist\intel64\compiler;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Windows\System32\OpenSSH\;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\Program Files\NVIDIA Corporation\NVIDIA NvDLISR;C:\Program Files (x86)\Microsoft SQL Server\100\Tools\Binn\;C:\Program Files\Microsoft SQL Server\100\Tools\Binn\;C:\Program Files\Microsoft SQL Server\100\DTS\Binn\;C:\Program Files\Common Files\Autodesk Shared\;C:\Program Files\Microsoft SQL Server\120\Tools\Binn\;C:\Program Files\dotnet\;C:\Program Files (x86)\dotnet\;F:\develop\MYSQL\mysql-5.7.35-winx64\bin;F:\develop\apache-maven-3.6.1\bin;F:\develop\python39\Lib\site-packages;F:\develop\Git\cmd;F:\develop\redis\;F:\Program Files (x86)\NetSarang\Xshell 7\;C:\Program Files (x86)\Gpg4win\..\GnuPG\bin;F:\Program Files (x86)\XFTP7\;F:\Program Files (x86)\TortoiseGit2.13.0.1\bin;F:\develop\GO\bin;F:\develop\Toolbox\scripts;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\WINDOWS\System32\OpenSSH\;F:\develop\node.js\;C:\Program Files (x86)\Windows Kits\10\Windows Performance Toolkit\;F:\develop\graalvm-jdk-17_windows-x64_bin\graalvm-jdk-17.0.8+9.1\bin;F:\develop\node.js\node_global;F:\develop\ideasoftware\Anaconda3;F:\develop\ideasoftware\Anaconda3\Library\mingw-w64\bin;F:\develop\ideasoftware\Anaconda3\Library\usr\bin;F:\develop\ideasoftware\Anaconda3\Library\bin;F:\develop\ideasoftware\Anaconda3\Scripts;C:\Users\??\AppData\Local\Microsoft\WindowsApps;%PyCharm Community Edition%;C:\Users\??\.dotnet\tools;F:\develop\Microsoft VS Code\bin;%PyCharm%;F:\qqgame\Hall.57734\;F:\develop\ideasoftware\WebStorm 2022.2\bin;C:\Users\??\go\bin;F:\develop\gradle-8.1.1\bin;F:\Program Files (x86)\ffmpeg\ffmpeg-2023-06-08-git-024c30aa3b-essentials_build\bin;C:\Users\??\AppData\Local\Microsoft\WindowsApps;C:\Users\??\AppData\Roaming\npm' \
'TEMP=C:\Users\??\AppData\Local\Temp' \
USE_NATIVE_IMAGE_JAVA_PLATFORM_MODULE_SYSTEM=true \
'F:\develop\graalvm-jdk-17_windows-x64_bin\graalvm-jdk-17.0.8+9.1\bin\java.exe' \
-XX:+UseParallelGC \
-XX:+UnlockExperimentalVMOptions \
-XX:+EnableJVMCI \
-Dtruffle.TrustAllTruffleRuntimeProviders=true \
-Dtruffle.TruffleRuntime=com.oracle.truffle.api.impl.DefaultTruffleRuntime \
-Dgraalvm.ForcePolyglotInvalid=true \
-Dgraalvm.locatorDisabled=true \
-Dsubstratevm.IgnoreGraalVersionCheck=true \
--add-exports=java.base/com.sun.crypto.provider=org.graalvm.nativeimage.builder \
--add-exports=java.base/jdk.internal.access.foreign=org.graalvm.nativeimage.builder \
--add-exports=java.base/jdk.internal.event=org.graalvm.nativeimage.builder \
--add-exports=java.base/jdk.internal.loader=org.graalvm.nativeimage.builder,org.graalvm.truffle \
--add-exports=java.base/jdk.internal.logger=org.graalvm.nativeimage.builder \
--add-exports=java.base/jdk.internal.misc=com.oracle.svm.svm_enterprise,org.graalvm.nativeimage.builder,org.graalvm.nativeimage.objectfile,org.graalvm.nativeimage.pointsto \
--add-exports=java.base/jdk.internal.module=jdk.internal.vm.compiler,org.graalvm.nativeimage.base,org.graalvm.nativeimage.builder \
--add-exports=java.base/jdk.internal.org.objectweb.asm=org.graalvm.nativeimage.builder \
--add-exports=java.base/jdk.internal.perf=org.graalvm.nativeimage.builder \
--add-exports=java.base/jdk.internal.platform=org.graalvm.nativeimage.builder \
--add-exports=java.base/jdk.internal.ref=org.graalvm.nativeimage.builder,org.graalvm.nativeimage.objectfile \
--add-exports=java.base/jdk.internal.reflect=org.graalvm.nativeimage.builder \
--add-exports=java.base/jdk.internal.util=org.graalvm.nativeimage.builder \
--add-exports=java.base/jdk.internal.vm.annotation=org.graalvm.nativeimage.builder \
--add-exports=java.base/jdk.internal.vm=org.graalvm.nativeimage.builder \
--add-exports=java.base/sun.invoke.util=org.graalvm.nativeimage.builder \
--add-exports=java.base/sun.net=org.graalvm.nativeimage.builder \
--add-exports=java.base/sun.nio.ch=org.graalvm.nativeimage.builder,org.graalvm.nativeimage.objectfile \
--add-exports=java.base/sun.reflect.annotation=org.graalvm.nativeimage.builder \
--add-exports=java.base/sun.reflect.generics.factory=org.graalvm.nativeimage.builder \
--add-exports=java.base/sun.reflect.generics.reflectiveObjects=org.graalvm.nativeimage.builder \
--add-exports=java.base/sun.reflect.generics.repository=org.graalvm.nativeimage.builder \
--add-exports=java.base/sun.reflect.generics.scope=org.graalvm.nativeimage.builder \
--add-exports=java.base/sun.reflect.generics.tree=org.graalvm.nativeimage.builder \
--add-exports=java.base/sun.security.jca=org.graalvm.nativeimage.builder \
--add-exports=java.base/sun.security.provider=org.graalvm.nativeimage.builder \
--add-exports=java.base/sun.security.ssl=org.graalvm.nativeimage.builder \
--add-exports=java.base/sun.security.util=org.graalvm.nativeimage.builder \
--add-exports=java.base/sun.security.x509=org.graalvm.nativeimage.builder \
--add-exports=java.base/sun.text.spi=org.graalvm.nativeimage.builder \
--add-exports=java.base/sun.util.calendar=org.graalvm.nativeimage.builder \
--add-exports=java.base/sun.util.cldr=org.graalvm.nativeimage.builder \
--add-exports=java.base/sun.util.locale.provider=org.graalvm.nativeimage.builder \
--add-exports=java.base/sun.util.locale=org.graalvm.nativeimage.builder \
--add-exports=java.base/sun.util.resources=org.graalvm.nativeimage.builder \
--add-exports=java.base/sun.util=org.graalvm.nativeimage.builder \
--add-exports=java.management.rmi/com.sun.jmx.remote.internal.rmi=org.graalvm.nativeimage.builder \
--add-exports=java.management.rmi/com.sun.jmx.remote.protocol.rmi=org.graalvm.nativeimage.builder \
--add-exports=java.management/com.sun.jmx.mbeanserver=org.graalvm.nativeimage.builder \
--add-exports=java.management/sun.management=org.graalvm.nativeimage.builder,org.graalvm.nativeimage.pointsto \
--add-exports=java.rmi/sun.rmi.server=org.graalvm.nativeimage.builder \
--add-exports=java.xml.crypto/org.jcp.xml.dsig.internal.dom=org.graalvm.nativeimage.builder \
--add-exports=jdk.internal.vm.ci/jdk.vm.ci.aarch64=com.oracle.graal.graal_enterprise,com.oracle.svm.svm_enterprise,jdk.internal.vm.compiler,org.graalvm.nativeimage.builder,org.graalvm.nativeimage.objectfile \
--add-exports=jdk.internal.vm.ci/jdk.vm.ci.amd64=com.oracle.graal.graal_enterprise,com.oracle.svm.svm_enterprise,jdk.internal.vm.compiler,org.graalvm.nativeimage.builder,org.graalvm.nativeimage.objectfile \
--add-exports=jdk.internal.vm.ci/jdk.vm.ci.code.site=com.oracle.svm.svm_enterprise,jdk.internal.vm.compiler,org.graalvm.nativeimage.builder \
--add-exports=jdk.internal.vm.ci/jdk.vm.ci.code.stack=jdk.internal.vm.compiler,org.graalvm.nativeimage.builder \
--add-exports=jdk.internal.vm.ci/jdk.vm.ci.code=com.oracle.graal.graal_enterprise,com.oracle.svm.svm_enterprise,jdk.internal.vm.compiler,org.graalvm.nativeimage.builder,org.graalvm.nativeimage.objectfile,org.graalvm.nativeimage.pointsto \
--add-exports=jdk.internal.vm.ci/jdk.vm.ci.common=com.oracle.graal.graal_enterprise,com.oracle.svm.svm_enterprise,jdk.internal.vm.compiler,org.graalvm.nativeimage.builder,org.graalvm.nativeimage.pointsto \
--add-exports=jdk.internal.vm.ci/jdk.vm.ci.hotspot.aarch64=jdk.internal.vm.compiler \
--add-exports=jdk.internal.vm.ci/jdk.vm.ci.hotspot.amd64=jdk.internal.vm.compiler \
--add-exports=jdk.internal.vm.ci/jdk.vm.ci.hotspot=com.oracle.graal.graal_enterprise,jdk.internal.vm.compiler,org.graalvm.nativeimage.builder,org.graalvm.nativeimage.pointsto \
--add-exports=jdk.internal.vm.ci/jdk.vm.ci.meta=com.oracle.graal.graal_enterprise,com.oracle.svm.svm_enterprise,jdk.internal.vm.compiler,org.graalvm.nativeimage.base,org.graalvm.nativeimage.builder,org.graalvm.nativeimage.objectfile,org.graalvm.nativeimage.pointsto \
--add-exports=jdk.internal.vm.ci/jdk.vm.ci.runtime=com.oracle.graal.graal_enterprise,jdk.internal.vm.compiler,org.graalvm.nativeimage.builder,org.graalvm.nativeimage.pointsto \
--add-exports=jdk.internal.vm.ci/jdk.vm.ci.services=com.oracle.graal.graal_enterprise,com.oracle.svm.svm_enterprise,jdk.internal.vm.compiler,org.graalvm.nativeimage.builder \
--add-exports=jdk.jfr/jdk.jfr.events=org.graalvm.nativeimage.builder \
--add-exports=jdk.jfr/jdk.jfr.internal.handlers=org.graalvm.nativeimage.builder \
--add-exports=jdk.jfr/jdk.jfr.internal.jfc=org.graalvm.nativeimage.builder \
--add-exports=jdk.jfr/jdk.jfr.internal=org.graalvm.nativeimage.builder \
--add-exports=jdk.management.agent/jdk.internal.agent=org.graalvm.nativeimage.builder \
--add-exports=jdk.management/com.sun.management.internal=org.graalvm.nativeimage.builder \
--add-exports=org.graalvm.truffle/com.oracle.truffle.api.object=com.oracle.graal.graal_enterprise \
-XX:+UseJVMCINativeLibrary \
-Xss10m \
-XX:MaxRAMPercentage=32.013979929906796 \
-XX:GCTimeRatio=19 \
-XX:+ExitOnOutOfMemoryError \
-Djava.awt.headless=true \
'-Dorg.graalvm.vendor=Oracle Corporation' \
-Dorg.graalvm.vendorurl=https://www.graalvm.org/ \
'-Dorg.graalvm.vendorversion=Oracle GraalVM 17.0.8+9.1' \
-Dorg.graalvm.version=23.0.1 \
-Dcom.oracle.graalvm.isaot=true \
-Djava.system.class.loader=com.oracle.svm.hosted.NativeImageSystemClassLoader \
-Xshare:off \
-Djdk.internal.lambda.disableEagerInitialization=true \
-Djdk.internal.lambda.eagerlyInitialize=false \
-Djava.lang.invoke.InnerClassLambdaMetafactory.initializeLambdas=false \
--add-modules=ALL-DEFAULT \
--module-path \
'F:\develop\graalvm-jdk-17_windows-x64_bin\graalvm-jdk-17.0.8+9.1\lib\truffle\truffle-api.jar;F:\develop\graalvm-jdk-17_windows-x64_bin\graalvm-jdk-17.0.8+9.1\lib\svm\builder\native-image-base.jar;F:\develop\graalvm-jdk-17_windows-x64_bin\graalvm-jdk-17.0.8+9.1\lib\svm\builder\objectfile.jar;F:\develop\graalvm-jdk-17_windows-x64_bin\graalvm-jdk-17.0.8+9.1\lib\svm\builder\pointsto.jar;F:\develop\graalvm-jdk-17_windows-x64_bin\graalvm-jdk-17.0.8+9.1\lib\svm\builder\svm-enterprise.jar;F:\develop\graalvm-jdk-17_windows-x64_bin\graalvm-jdk-17.0.8+9.1\lib\svm\builder\svm.jar' \
--module \
org.graalvm.nativeimage.builder/com.oracle.svm.hosted.NativeImageGeneratorRunner \
-imagecp \
'F:\study\code\myProject\Graalvm-SpringBoot-Demo\target\Graalvm-SpringBoot-Demo-0.0.1-SNAPSHOT.jar' \
-imagemp \
'F:\develop\graalvm-jdk-17_windows-x64_bin\graalvm-jdk-17.0.8+9.1\lib\svm\graal-microservices.jar;F:\develop\graalvm-jdk-17_windows-x64_bin\graalvm-jdk-17.0.8+9.1\lib\svm\library-support.jar' \
'-H:CLibraryPath=F:\develop\graalvm-jdk-17_windows-x64_bin\graalvm-jdk-17.0.8+9.1\lib\svm\clibraries\windows-amd64' \
'-H:Path=F:\study\code\myProject\Graalvm-SpringBoot-Demo\target' \
'-H:Name@manifest from file:///F:/study/code/myProject/Graalvm-SpringBoot-Demo/target/Graalvm-SpringBoot-Demo-0.0.1-SNAPSHOT.jar=Graalvm-SpringBoot-Demo-0.0.1-SNAPSHOT' \
'-H:Class@manifest from file:///F:/study/code/myProject/Graalvm-SpringBoot-Demo/target/Graalvm-SpringBoot-Demo-0.0.1-SNAPSHOT.jar=org.springframework.boot.loader.JarLauncher' \
-H:FallbackThreshold=0 \
'-H:Features@jar:file:///F:/develop/graalvm-jdk-17_windows-x64_bin/graalvm-jdk-17.0.8+9.1/lib/svm/library-support.jar!/META-INF/native-image/com.oracle.svm/thirdparty/native-image.properties=com.oracle.svm.thirdparty.gson.GsonFeature' \
'-H:Features@jar:file:///F:/develop/graalvm-jdk-17_windows-x64_bin/graalvm-jdk-17.0.8+9.1/lib/svm/library-support.jar!/META-INF/native-image/com.oracle.svm/polyglot/native-image.properties=com.oracle.svm.polyglot.groovy.GroovyIndyInterfaceFeature,com.oracle.svm.polyglot.scala.ScalaFeature'
]
========================================================================================================================
GraalVM Native Image: Generating 'Graalvm-SpringBoot-Demo-0.0.1-SNAPSHOT' (executable)...
========================================================================================================================
For detailed information and explanations on the build output, visit:
https://github.com/oracle/graal/blob/master/docs/reference-manual/native-image/BuildOutput.md
------------------------------------------------------------------------------------------------------------------------
[1/8] Initializing...                                                                                    (7.3s @ 0.12GB)
 Java version: 17.0.8+9-LTS, vendor version: Oracle GraalVM 17.0.8+9.1
 Graal compiler: optimization level: 2, target machine: x86-64-v3, PGO: ML-inferred
 C compiler: cl.exe (microsoft, x64, 19.37.32820)
 Garbage collector: Serial GC (max heap size: 80% of RAM)
[2/8] Performing analysis...  [***]                                                                      (9.8s @ 0.52GB)
   3,797 (75.35%) of  5,039 types reachable
   4,745 (52.79%) of  8,988 fields reachable
  18,943 (48.99%) of 38,664 methods reachable
   1,265 types,     0 fields, and   578 methods registered for reflection
      70 types,    54 fields, and    59 methods registered for JNI access
       3 native libraries: crypt32, ncrypt, version
[3/8] Building universe...                                                                               (1.7s @ 0.50GB)
[4/8] Parsing methods...      [**]                                                                       (3.5s @ 0.62GB)
[5/8] Inlining methods...     [***]                                                                      (0.4s @ 0.67GB)
[6/8] Compiling methods...    [****]                                                                    (20.2s @ 1.09GB)
[7/8] Layouting methods...    [*]                                                                        (1.5s @ 1.40GB)
[8/8] Creating image...       [**]                                                                       (1.9s @ 1.58GB)
   8.96MB (52.19%) for code area:     9,792 compilation units
   7.99MB (46.56%) for image heap:  128,038 objects and 5 resources
 218.75kB ( 1.24%) for other data
  17.16MB in total
------------------------------------------------------------------------------------------------------------------------
Top 10 origins of code area:                                Top 10 object types in image heap:
   6.54MB java.base                                            1.75MB byte[] for code metadata
   1.70MB svm.jar (Native Image)                             995.66kB byte[] for java.lang.String
 194.72kB Graalvm-SpringBoot-Demo-0.0.1-SNAPSHOT.jar         945.02kB byte[] for general heap data
 169.74kB java.logging                                       919.50kB java.lang.String
 122.71kB com.oracle.svm.svm_enterprise                      678.38kB java.lang.Class
  51.19kB jdk.crypto.mscapi                                  355.04kB char[]
  32.76kB jdk.crypto.ec                                      319.97kB java.util.HashMap$Node
  32.62kB org.graalvm.sdk                                    177.98kB com.oracle.svm.core.hub.DynamicHubCompanion
  31.31kB org.graalvm.nativeimage.base                       174.18kB byte[] for reflection metadata
  15.61kB jdk.internal.vm.compiler                           148.84kB byte[] for embedded resources
  19.70kB for 5 more packages                                  1.27MB for 954 more object types
------------------------------------------------------------------------------------------------------------------------
Recommendations:
 PGO:  Use Profile-Guided Optimizations ('--pgo') for improved throughput.
 HEAP: Set max heap for improved and more predictable memory usage.
 CPU:  Enable more CPU features with '-march=native' for improved performance.
 QBM:  Use the quick build mode ('-Ob') to speed up builds during development.
 BRPT: Try out the new build reports with '-H:+BuildReport'.
------------------------------------------------------------------------------------------------------------------------
                        1.7s (3.6% of total time) in 107 GCs | Peak RSS: 2.27GB | CPU load: 8.47
------------------------------------------------------------------------------------------------------------------------
Produced artifacts:

Could not find class [com.example.GraalvmSpringBootDemoApplication__ApplicationContextInitializer]

你现在使用的是应该是

mvn native:compile-no-fork

报错原是缺少一些spring boot的AOT元文件信息,正确的做法是使用下面的命令:

mvn clean package -Pnative

并且查看插件是否缺少

<build>
        <plugins>
            <plugin>
                <groupId>org.graalvm.buildtools</groupId>
                <artifactId>native-maven-plugin</artifactId>
                <configuration>
                    <!-- imageName用于设置生成的二进制文件名称 -->
                    <imageName>${project.artifactId}</imageName>
                    <!-- mainClass用于指定main方法类路径 -->
                    <mainClass>${main-class}</mainClass>
                </configuration>
                <executions>
                    <execution>
                        <id>build-native</id>
                        <goals>
                            <goal>compile-no-fork</goal>
                        </goals>
                        <phase>package</phase>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <configuration>
                    <excludes>
                        <exclude>
                            <groupId>org.projectlombok</groupId>
                            <artifactId>lombok</artifactId>
                        </exclude>
                    </excludes>
                </configuration>
            </plugin>
        </plugins>
    </build>
相关实践学习
使用SQL语句管理索引
本次实验主要介绍如何在RDS-SQLServer数据库中,使用SQL语句管理索引。
SQL Server on Linux入门教程
SQL Server数据库一直只提供Windows下的版本。2016年微软宣布推出可运行在Linux系统下的SQL Server数据库,该版本目前还是早期预览版本。本课程主要介绍SQLServer On Linux的基本知识。 相关的阿里云产品:云数据库RDS&nbsp;SQL Server版 RDS SQL Server不仅拥有高可用架构和任意时间点的数据恢复功能,强力支撑各种企业应用,同时也包含了微软的License费用,减少额外支出。 了解产品详情:&nbsp;https://www.aliyun.com/product/rds/sqlserver
目录
相关文章
|
Java
103.【Java Microbenchmark Harness】(三)
103.【Java Microbenchmark Harness】
48 0
103.【Java Microbenchmark Harness】(三)
|
6月前
|
Oracle Java 关系型数据库
Java之基础认识Java
Java,由Sun公司于1995年推出,现归Oracle所有,提供Java SE、EE和ME版本,分别针对桌面、企业及嵌入式应用。Java语言因友好性被广泛使用,其命名灵感来源于爪哇岛咖啡。学习Java可从下载Oracle JDK开始,国内有Alibaba的AJDK作为替代。Java EE常用于企业应用开发。Java可用于各种软件、移动应用、大数据、云计算和嵌入式领域。开发流程包括配置环境、编码、调试、测试和部署。
31 0
|
6月前
|
Oracle Java 关系型数据库
|
小程序 Java 编译器
初识java(下)
初识java(下)
86 0
|
Java API 数据安全/隐私保护
JAVA知识——JAVA基础(五)
JAVA知识——JAVA基础
47 0
|
Java 大数据 关系型数据库
初识java(上)
初识java(上)
80 0
|
网络协议 Java
JAVA知识——JAVA基础(六)
JAVA知识——JAVA基础
61 0
|
存储 Java API
JAVA知识——JAVA基础(一)
JAVA知识——JAVA基础
67 0
|
存储 安全 Java
JAVA知识——JAVA基础(二)
JAVA知识——JAVA基础
42 0
|
存储 Java API
JAVA知识——JAVA基础(三)
JAVA知识——JAVA基础
62 0