1.GraalVM 版本下载java地址
https://www.graalvm.org/downloads/
这边我选择java17长期支持版本和window系统方式。
本次安装电脑window10专业版本。
2.下载好后,进行解压
tar -zxvf apache-maven-3.9.8-bin.tar.gz
3.增加变量
名称:GRAALVM_HOME
路径:C:\soft\graalvm-jdk-17.0.11+7.1
Path 增加 %GRAALVM_HOME%\bin
4. 安装成功后,进行查看
D:\javatest\src\main\java>where java
C:\soft\graalvm-jdk-17.0.11+7.1\bin\java.exe
C:\soft\jdk1.8.0_152\bin\java.exe
D:\javatest\src\main\java>where gu
C:\soft\graalvm-jdk-17.0.11+7.1\bin\gu.cmd
到这边恭喜您成功安装了graalvm-jdk。
5. 安装
Visual Studio 下载网址:https://visualstudio.microsoft.com/zh-hans/downloads/
本次安装的是visual studio community 版本
6.下载后打开选择,建议用稳定版本。
选择表黄的部分c++桌面开发和右侧标黄的组件。
6. 安装成功后,执行 helloworld.java文件
public class helloworld {public static void main(String[] args) throws InterruptedException {Thread.sleep(1000);System.out.println("hello world");Thread.sleep(1000);}
}
javac helloworld.java
native-image helloworld
D:\javatest\src\main\java>javac helloworld.javaD:\javatest\src\main\java>native-image helloworld
------------------------------------------------------------------------------------------------------------------------
[1/8] Initializing... (14.2s @ 0.17GB)Java version: 17.0.11+7-LTS, vendor version: Oracle GraalVM 17.0.11+7.1Graal compiler: optimization level: 2, target machine: x86-64-v3, PGO: ML-inferredC compiler: cl.exe (microsoft, x64, 19.40.33811)Garbage collector: Serial GC (max heap size: 80% of RAM)
[2/8] Performing analysis... [*****] (5.7s @ 0.24GB)1,816 (59.40%) of 3,057 types reachable1,686 (45.56%) of 3,701 fields reachable7,656 (35.87%) of 21,344 methods reachable621 types, 0 fields, and 284 methods registered for reflection53 types, 30 fields, and 48 methods registered for JNI access1 native library: version
[3/8] Building universe... (0.9s @ 0.26GB)
[4/8] Parsing methods... [*] (1.7s @ 0.27GB)
[5/8] Inlining methods... [***] (0.5s @ 0.26GB)
[6/8] Compiling methods... [****] (15.7s @ 0.30GB)
[7/8] Layouting methods... [*] (0.5s @ 0.29GB)
[8/8] Creating image... [*] (1.1s @ 0.32GB)2.81MB (44.22%) for code area: 3,450 compilation units 3.46MB (54.39%) for image heap: 49,016 objects and 1 resources90.44kB ( 1.39%) for other data6.36MB in total
------------------------------------------------------------------------------------------------------------------------
Top 10 origins of code area: Top 10 object types in image heap:1.46MB java.base 540.98kB byte[] for code metadata1.15MB svm.jar (Native Image) 413.68kB byte[] for java.lang.String70.93kB com.oracle.svm.svm_enterprise 324.76kB char[]34.21kB org.graalvm.nativeimage.base 324.21kB java.lang.String32.47kB org.graalvm.sdk 298.77kB java.lang.Class19.34kB jdk.internal.vm.ci 252.51kB byte[] for general heap data12.82kB jdk.internal.vm.compiler 150.00kB java.util.HashMap$Node1.75kB helloworld 79.13kB java.lang.Object[]1.17kB jdk.proxy3 70.94kB com.oracle.svm.core.hub.DynamicHubCompanion1.15kB jdk.proxy1 69.75kB byte[] for reflection metadata360.00B for 1 more packages 432.83kB for 496 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.0s (2.3% of total time) in 258 GCs | Peak RSS: 0.82GB | CPU load: 3.73
------------------------------------------------------------------------------------------------------------------------
Produced artifacts:D:\javatest\src\main\java\helloworld.exe (executable)
========================================================================================================================
Finished generating 'helloworld' in 40.9s.
最后单击运行 helloworld.exe可以运行了
8. 如果看到这边,你跟我一样安装的不是特别顺利
出现了以下报错 Visual Studio 2022 没有安装成功
D:\javatest\src\main\java\hello>native-image hello.hellowrold
Error: Failed to find 'vcvarsall.bat' in a Visual Studio installation.
Please make sure that Visual Studio 2022 version 17.1.0 or later is installed on your system. You can download it at https://visualstudio.microsoft.com/
downloads/. If this error persists, please try and run GraalVM Native Image in an x64 Native Tools Command Prompt or file a ticket.
最关键的一步骤过来了,需要安装手动安装VC_redist.x64.exe和VC_redist.x86.exe。
找到这个目录C:\ProgramData\Microsoft\VisualStudio\Packages
![在这里插入图片描述](https://img-blog.csdnimg.cn/direct/3fbce202fce14310a395c1443ca3a23e.png
搜索VC_redist,两个都需要安装。安装好之后必须重启电脑。
最后更多里面选择修复。
9. 过程很坎坷,到这边恭喜你成功。
10. 参考文档:https://blog.csdn.net/jpkopkop/article/details/127675664 https://blog.csdn.net/tangdou369098655/article/details/135738459