graalVM的正确安装姿势

抱怨:实在是受不了windows啦,装点什么都特费劲。

预备

本机环境:windows 11 家庭版

graalVM版本:graalvm-jdk-17.0.9 (https://www.graalvm.org/downloads/#)

自己学习用哪个都可以

visual studio 版本:visual studio Community 2022

visual studio 安装步骤

1、安装

https://visualstudio.microsoft.com/zh-hans/free-developer-offers/

选择 Community

勾选这两项

单个组件勾选,选windows 10 SDK一个版本即可,为配置环境变量准备

安装目录尽量不更换

点击安装,根据网速情况决定安装时间。

2、环境变量配置

// 新增 LIB
D:Windows Kits10Lib10.0.18362.0umd
D:Windows Kits10Lib10.0.18362.0ucrtd

// 新增 INCLUDE
D:Windows Kits10Include10.0.18362.0ucrt
D:Windows Kits10Include10.0.18362.0um
D:Windows Kits10Include10.0.18362.0winrt

新增include

这里注意上面强调的安装目录,和Windows Kits目录。大部分情况按照默认安装,Windows Kits目录应该在C盘(C:Program Files (x86)Windows Kits),这里之前安装其他软件可能改过什么东西,导致再D盘。

抱怨:这些都是windows自己开发平台东西,还需要配置一遍环境变量,真心不理解。

GraalVM JAVA 17 安装

1、解压

D: oolsjavagraalvm-jdk-17.0.9+11.1

2、配置环境变量

// 新增 JAVA_HOME
D:	oolsjavagraalvm-jdk-17.0.9+11.1
// 新增 CLASSPATH
.;%JAVA_HOME%lib;%JAVA_HOME%lib	ools.jar
// 追加 path
%JAVA_HOME%bin

配置JAVA_HOME

配置CLASSPATH

追加PATH

运行

1、编写代码

public class HelloWorld {
    public static void main(String[] args) {
        System.out.println("HELLO WORLD");
    }
}

2、编译

native-image HelloWorld
PS D:workspace_colagraalvm-demosrc	estjavacomexampledemo> native-image HelloWorld
========================================================================================================================
GraalVM Native Image: Generating 'helloworld' (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.0s @ 0.12GB)
 Java version: 17.0.9+11-LTS, vendor version: Oracle GraalVM 17.0.9+11.1
 Graal compiler: optimization level: 2, target machine: x86-64-v3, PGO: ML-inferred
 C compiler: cl.exe (microsoft, x64, 19.38.33133)
 Garbage collector: Serial GC (max heap size: 80% of RAM)
[2/8] Performing analysis...  [****]                                                                     (7.4s @ 0.22GB)
   1,818 (59.33%) of  3,064 types reachable
   1,681 (45.72%) of  3,677 fields reachable
   7,612 (35.75%) of 21,294 methods reachable
     620 types,     0 fields, and   284 methods registered for reflection
      53 types,    30 fields, and    48 methods registered for JNI access
       1 native library: version
[3/8] Building universe...                                                                               (1.1s @ 0.27GB)
[4/8] Parsing methods...      [**]                                                                       (2.5s @ 0.20GB)
[5/8] Inlining methods...     [***]                                                                      (0.7s @ 0.22GB)
[6/8] Compiling methods...    [****]                                                                    (20.3s @ 0.47GB)
[7/8] Layouting methods...    [*]                                                                        (0.7s @ 0.26GB)
[8/8] Creating image...       [*]                                                                        (1.7s @ 0.34GB)
   2.80MB (44.23%) for code area:     3,431 compilation units
   3.45MB (54.47%) for image heap:   48,812 objects and 1 resources
  84.34kB ( 1.30%) for other data
   6.33MB in total
------------------------------------------------------------------------------------------------------------------------
Top 10 origins of code area:                                Top 10 object types in image heap:
   1.47MB java.base                                          533.83kB byte[] for code metadata
   1.14MB svm.jar (Native Image)                             411.80kB byte[] for java.lang.String
  70.88kB com.oracle.svm.svm_enterprise                      324.76kB char[]
  34.18kB org.graalvm.nativeimage.base                       322.48kB java.lang.String
  32.47kB org.graalvm.sdk                                    299.12kB java.lang.Class
  19.36kB jdk.internal.vm.ci                                 251.41kB byte[] for general heap data
  14.41kB jdk.internal.vm.compiler                           148.88kB java.util.HashMap$Node
   1.17kB jdk.proxy3                                          79.06kB java.lang.Object[]
   1.15kB jdk.proxy1                                          71.02kB com.oracle.svm.core.hub.DynamicHubCompanion
  360.00B jdk.proxy2                                          69.51kB byte[] for reflection metadata
   54.00B for 1 more packages                                431.61kB for 499 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.5s (3.3% of total time) in 115 GCs | Peak RSS: 1.02GB | CPU load: 5.72
------------------------------------------------------------------------------------------------------------------------
Produced artifacts:
 D:workspace_colagraalvm-demosrc	estjavacomexampledemohelloworld.exe (executable)
========================================================================================================================
Finished generating 'helloworld' in 42.5s.

3、执行

./helloworld

输出:

输出


PS1:网上有配置如下环境变量的,但是我配置这些就会报错,找不到'winapifamily.h'

// 追加 path
C:Program FilesMicrosoft Visual Studio2022CommunityVCToolsMSVC14.38.33130binHostx64d

// 新增 LIB 包含
C:Program FilesMicrosoft Visual Studio2022CommunityVCToolsMSVC14.38.33130libd
// 新增 INCLUDE
C:Program FilesMicrosoft Visual Studio2022CommunityVCToolsMSVC14.38.33130include

PS2: 报如下错误

========================================================================================================================
GraalVM Native Image: Generating 'helloworld.java' (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...                                                                                    (0.0s @ 0.08GB)
Error: Main entry point class 'HelloWorld.java' neither found on
classpath: 'D:workspace_colagraalvm-demosrc	estjavacomexampledemo' nor
modulepath: 'D:	oolsjavagraalvm-jdk-17.0.9+11.1libsvmgraal-microservices.jar;D:	oolsjavagraalvm-jdk-17.0.9+11.1libsvmlibrary-support.jar'.
Error: Use -H:+ReportExceptionStackTraces to print stacktrace of underlying exception

原因就是有可能,visual studio2022没有安装,或者上面visual studio 的环境变量没有配置。

——————————

定风波·次高左藏使君韵

作者:苏轼

万里黔中一漏天,屋居终日似乘船。及至重阳天也霁,催醉,鬼门关外蜀江前。

莫笑老翁犹气岸,君看,几人黄菊上华颠?戏马台南追两谢,驰射,风流犹拍古人肩。


展开阅读全文

页面更新:2024-05-02

标签:台南   使君   关外   老翁   重阳   费劲   环境变量   姿势   正确   版本   情况   目录

1 2 3 4 5

上滑加载更多 ↓
推荐阅读:
友情链接:
更多:

本站资料均由网友自行发布提供,仅用于学习交流。如有版权问题,请与我联系,QQ:4156828  

© CopyRight 2008-2024 All Rights Reserved. Powered By bs178.com 闽ICP备11008920号-3
闽公网安备35020302034844号

Top