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
目录
相关文章
|
7月前
|
Oracle Java 关系型数据库
Java基础之认识java
Java,由Sun公司创立,现归Oracle所有,是一种高级编程语言,以Oak为初名,后因咖啡联想改称Java。Java SDK可在Oracle官网下载,国内有阿里巴巴的AJDK作为替代。Java分为SE、EE和ME版本,分别针对桌面、企业及嵌入式应用。常用的是Java EE,适合开发服务器软件。Java应用广泛,涵盖桌面、企业、移动和Web应用,以及大数据、云计算和游戏开发等领域。学习Java涉及搭建环境、编码、调试、测试和部署等步骤。
54 0
|
Java API 数据安全/隐私保护
JAVA知识——JAVA基础(五)
JAVA知识——JAVA基础
50 0
|
Java Maven
Native-java(4)
Native-java(4)
54 1
|
Java Linux Maven
Native-java(5)
Native-java(5)
62 1
|
Java C++ Spring
Native-java(2)
Native-java(2)
47 0
|
Oracle Java 开发工具
Native-java(1)
Native-java(1)
106 0
|
存储 安全 Java
JAVA知识——JAVA基础(二)
JAVA知识——JAVA基础
44 0
|
存储 Java API
JAVA知识——JAVA基础(三)
JAVA知识——JAVA基础
65 0
|
存储 Java API
JAVA知识——JAVA基础(一)
JAVA知识——JAVA基础
70 0
|
安全 Java C++
Java本地方法/Java native方法/JNI
Java本地方法/Java native方法/JNI
205 0