公众号:架构师与哈苏
关注公众号进入it交流群! 公众号:架构师与哈苏 不定时都会推送一些实用的干货。。。

graalvm jdk下载
https://www.graalvm.org/downloads/

把graalvm加入环境变量和就是JAVA_HOME
安装native-image
gu.cmd install native-image

问题:
Error: Default native-compiler executable 'cl.exe' not found via environment variable PATH
Error: To prevent native-toolchain checking provide command-line option -H:-CheckToolchain
安装Visual Studio
https://visualstudio.microsoft.com/zh-hans/downloads/

添加环境变量:
在PATH中添加:C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.16.27023\bin\HostX64\x64

下载windows kit
https://developer.microsoft.com/zh-cn/windows/downloads/windows-sdk/
INCLUDE=
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\um;
C:\Program Files (x86)\Windows Kits\10\Include\10.0.22621.0\shared;
C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.16.27023\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;
C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.16.27023\lib\x64;
不要带分号

把这两个变量添加进入path:

启动报错
com.oracle.svm.core.util.UserError$UserException: Main entry point class 'com.xxx.Application' not found.
参考:
https://github.com/graalvm/native-build-tools/issues/213
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>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>3.0.6</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.example</groupId>
    <artifactId>graalvm-demo2</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>graalvm-demo2</name>
    <description>graalvm-demo2</description>
    <properties>
        <java.version>17</java.version>
    </properties>
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <optional>true</optional>
        </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>
                <executions>
                    <execution>
                        <id>build-native</id>
                        <goals>
                            <goal>compile-no-fork</goal>
                        </goals>
                        <phase>package</phase>
                    </execution>
                </executions>
                <configuration>
                    <mainClass>com.example.graalvmdemo2.GraalvmDemo2Application</mainClass>
                    <skipNativeTests>true</skipNativeTests>
                    <verbose>true</verbose>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <configuration>
                    <mainClass>com.example.graalvmdemo2.GraalvmDemo2Application</mainClass>
                    <excludes>
                        <exclude>
                            <groupId>org.projectlombok</groupId>
                            <artifactId>lombok</artifactId>
                        </exclude>
                    </excludes>
                </configuration>
            </plugin>
        </plugins>
    </build>

</project>

GraalvmDemo2Application.java

package com.example.graalvmspringpackage;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication(proxyBeanMethods = false)
public class GraalvmDemo2Application {

    public static void main(String[] args) {
        SpringApplication.run(GraalvmDemo2Application.class, args);
    }

}

打包

posted on 2023-04-28 13:10  公众号/架构师与哈苏  阅读(265)  评论(0编辑  收藏  举报