首页  

graalvm hello 实例     所属分类 graalvm 浏览量 354
云原生时代 Java应用缺点 启动慢, 占用内存多, 需要装jvm
GraalVM  AOT(ahead of time)编译  编译成本地镜像

https://www.graalvm.org/

https://github.com/graalvm/graalvm-ce-builds/releases/tag/vm-22.0.0.2
下载 graalvm-ce-java11-darwin-amd64-22.0.0.2.tar.gz

graalvm-ce-java11-22.0.0.2/Contents/Home/bin/gu install native-image
bin下 会出现 native-image

gu install native-image. 
gu is a utility that you get in a GraalVM. 
JAVA_HOME  set up to point to GraalVM

/Users/xxx/soft/graalvm/graalvm-ce-java11-22.0.0.2/Contents/Home/bin/native-image  graalvm.GraalvmHello

编译报错
Error: Main entry point class 'graalvm.GraalvmHello' not found.
Error: Use -H:+ReportExceptionStackTraces to print stacktrace of underlying exception
Error: Image build request failed with exit status 1

需要先编译生成 class 
/Users/xxx/soft/graalvm/graalvm-ce-java11-22.0.0.2/Contents/Home/bin/javac  graalvm/GraalvmHello.java
再执行 搞定
/Users/xxx/soft/graalvm/graalvm-ce-java11-22.0.0.2/Contents/Home/bin/native-image  graalvm.GraalvmHello

.
├── graalvm
│   ├── GraalvmHello.class
│   └── GraalvmHello.java
├── graalvm.graalvmhello
└── graalvm.graalvmhello.build_artifacts.txt


使用maven 注意 pom 里 graalvm.version 21.0.0 22.0.0 的找不到 export JAVA_HOME=/Users/xxx/soft/graalvm/graalvm-ce-java11-22.0.0.2/Contents/Home maven package 不设置 JAVA_HOME 报错 [ERROR] Failed to execute goal org.graalvm.nativeimage:native-image-maven-plugin:21.0.0:native-image (default) on project graalvmdemo: Could not find executable native-image in /Library/Java/JavaVirtualMachines/jdk1.8.0_221.jdk/Contents/Home/jre/jre/lib/svm/bin/native-image 编译过程比较慢 生成的可执行文件挺大的,一个helloworld 10M go hello 大小约 1.8M ./graalvmdemo hello,graalvm
各种 hello 可执行文件大小 graalvm 10165344 go 1865408 c 49424 c++ 55960
例子代码 https://gitee.com/dyyx/hellocode/tree/master/demo/graalvmdemo

上一篇     下一篇
quarkus 打包类型 quarkus.package.type

quarkus 配置优先级

JavaScript 模板引擎

jar 命令使用

protobuf 对象转 json string

jackson 直接把protobuf 数据对象 序列化成 json string