跳到正文
Skillpedia
API 与服务器(后端)22k · #10358

building-native-image

它能做什么

这项技能指导 AI 使用 GraalVM Native Image 构建 Java 应用、设置构建选项并解决问题。适合希望 Java 程序能作为单个原生可执行文件运行的开发人员。

适用场景

  • ✓你需要用 GraalVM 把 Java 程序变成原生可执行文件的时候。
  • ✓Native Image 构建或生成的应用因反射、JNI、资源或代理错误而失败的时候。
  • ✓你想更改 Native Image 构建选项,例如类路径、输出名称或优化级别的时候。

技能链接

https://github.com/oracle/graal/blob/master/docs/reference-manual/native-image/assets/skills/building-native-image/SKILL.md

复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。

使用方法

最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。

可直接粘贴的消息

请用这个技能帮我:https://github.com/oracle/graal/blob/master/docs/reference-manual/native-image/assets/skills/building-native-image/SKILL.md 阅读该链接中的 SKILL.md 文件,并在我的任务中按照它的说明来做。
想让你的 AI 自己找到这样的技能吗?安装免费的 Skillpedia MCP:只需一行,每次任务前它都会在 15,000+ 个技能中搜索。1 分钟完成安装 →

可以这样问 AI

“请帮我用 GraalVM Native Image 把我的 Java 应用构建成原生可执行文件。”

每周 5 个新技能,1 分钟读完。

工作原理

AI 会按步骤编译 Java 代码、运行 native-image 工具,并启动生成的结果。遇到错误时,它会查阅关于反射、资源和序列化的参考指南。

技术内容(原始 SKILL.md)

作者在 GitHub 上的英文原文。

​# Building Native Image

Prerequisites

  • Set JAVA_HOME to a GraalVM distribution if your Java program uses the Native Image SDK. If you do not know the path, ask the user to provide it. ​

Build and Run

  1. Compile your Java file with javac.
  2. Build the Native Image:
    $JAVA_HOME/bin/native-image <app-name>
    
  3. Run the resulting executable:
    ./app-name
    
  4. If Native Image cannot find your class file, set the classpath explicitly with the -cp option. ​

Troubleshooting

Reachability Metadata

If you encounter runtime errors related to reflection, JNI, resources, serialization, or dynamic proxies, consult references/reachability-metadata.md before attempting a fix. Use this reference for:

  • NoClassDefFoundError or MissingReflectionRegistrationError
  • MissingJNIRegistrationError
  • MissingResourceException (missing resource bundle)
  • Any user question about reflection, JNI, proxies, resources, resource bundles, or serialization in Native Image. ​

Native Image Options

To configure classpath, optimization level, output name, platform target, monitoring, or other CLI flags, see references/native-image-options.md.

Reference Files

Topic File
Native Image CLI options references/native-image-options.md
Missing reachability metadata references/reachability-metadata.md
常见问题

使用这项技能需要安装 GraalVM 吗?

需要。这项技能要求 JAVA_HOME 指向某个 GraalVM 发行版;如果 AI 不知道它的路径,会向你询问。

它能帮助处理哪些错误?

包括缺失反射注册、缺失 JNI 注册和缺失资源包等错误。

它能帮我更改构建选项吗?

能。它附有 Native Image 命令行选项参考,涵盖类路径、输出名称、平台目标等。

详情

作者的原始描述

Build and troubleshoot GraalVM Native Image applications. Use this skill to build Java applications with GraalVM Native Image, configure CLI options, or resolve build or runtime issues.

repo: oracle/graal

热度

GitHub 星标
22k
排名
#10358
许可证
—
更新时间
2026/11/2

这个技能有用吗?

0

登录 后即可投票。

评论

  • …

同一仓库的更多技能

相似技能