quarkus-native-and-container
它能做什么
这个工具帮助你创建更快、更高效的 Quarkus 代码版本,称为“原生可执行文件”(native executables)。它还能协助修复这一过程中出现的常见错误,并创建可在 Docker 等容器中运行、或在 Kubernetes 等平台上运行的软件包。
适用场景
- ✓当你希望 Quarkus 应用的启动速度大幅提升时。
- ✓当你准备让应用在 Kubernetes 等云环境中运行时。
- ✓当你在构建应用的原生版本时遇到错误。
技能链接
https://github.com/github/awesome-copilot/blob/main/skills/quarkus-native-and-container/SKILL.md复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。
使用方法
最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。
可直接粘贴的消息
适用于 Claude Code、Codex 或 Cursor:在项目文件夹中运行,即可安装该技能。
下载 SKILL.md,放进智能体的技能文件夹。
可以这样问 AI
“怎样为我的 Quarkus 应用创建原生可执行文件,并把它打包成 Docker 容器?”
每周 5 个新技能,1 分钟读完。
工作原理
这个工具会使用特定的 Maven 或 Gradle 命令,把 Quarkus 代码编译为原生可执行文件。如果出现错误,它会提供方法,注册在原生编译时需要特殊访问权限的代码部分,或者包含必要的文件。
技术内容(原始 SKILL.md)
作者在 GitHub 上的英文原文。
Quarkus Native and Container
Check the project's Quarkus version first. For generic (non-Quarkus) GraalVM work, use the optional java-add-graalvm-native-image-support skill if installed (otherwise see the GraalVM docs, https://www.graalvm.org/latest/reference-manual/native-image/).
Native build
# container build: no local GraalVM needed (Docker/Podman required)
./mvnw package -Dnative -Dquarkus.native.container-build=true
# local Mandrel/GraalVM (JAVA_HOME / GRAALVM_HOME must point to it)
./mvnw package -Dnative
# Gradle, Quarkus 3.10+ (add -Dquarkus.native.container-build=true without a local Mandrel)
./gradlew build -Dquarkus.native.enabled=true -Dquarkus.package.jar.enabled=false
# Gradle, older Quarkus
./gradlew build -Dquarkus.package.type=native
quarkus.package.type was deprecated in 3.10 (the 3.10 migration guide replaces it with quarkus.native.enabled and quarkus.package.jar.*); it is still accepted in 3.40 with a warning. Version gate verified with Gradle: on 3.9.5 -Dquarkus.native.enabled=true -Dquarkus.package.jar.enabled=false is ignored ("Unrecognized configuration key" warnings) and only a JVM quarkus-app is built, while -Dquarkus.package.type=native produces the native runner; on 3.10.0, 3.27.6 and 3.40.1 the new keys produce the native runner (3.10.0 also accepts the old key with the deprecation warning). The Maven native profile in the generated pom.xml already sets quarkus.native.enabled=true, quarkus.package.jar.enabled=false and skipITs=false when -Dnative is passed.
Local build verified on macOS arm64 with the Mandrel tarball for your Quarkus line from https://github.com/graalvm/mandrel/releases (mandrel-java25-macos-aarch64-25.0.4.1-Final.tar.gz for 3.40.1, extracted anywhere, JAVA_HOME pointing at its Contents/Home; Xcode command line tools are enough): 3.40.1 Maven package -Dnative took about 70 s and Gradle build with the two flags about 2.5 min; the runner is a Mach-O executable that starts in about 0.04 s, and ./mvnw verify -Dnative ran the *IT against it successfully. Quarkus checks the Mandrel/GraalVM version: 3.40 refuses 23.1 ("Out of date version of GraalVM or Mandrel detected ... Quarkus currently supports 25.0.0"), so use Mandrel 25 with 3.40 and mandrel-java21-macos-aarch64-23.1.12.1-Final with 3.27.6 (Maven verify -Dnative and Gradle both verified there).
Binary: target/*-runner (Maven) or build/*-runner (Gradle). A container build on macOS or Windows produces a Linux ELF that cannot run on the host: run it in a Linux container (for example docker run -v "$PWD/target:/w:ro" registry.access.redhat.com/ubi9/ubi-minimal /w/<name>-runner with the datasource passed through QUARKUS_DATASOURCE_* env vars), and note that ./mvnw verify -Dnative then fails in the *IT with Exit code is: '126'. Mandrel is Red Hat's GraalVM distribution for Quarkus; the container build pulls a Mandrel builder image matching the project (3.40.1 used quay.io/quarkus/ubi9-quarkus-mandrel-builder-image:jdk-25, Mandrel 25.0.4.1, about 2.5 minutes including the image pull); override it with quarkus.native.builder-image if needed. Native builds are slow and memory-hungry (several GB); do them in CI or on demand, not on every test run.
Common native failures
| Symptom | Fix |
|---|---|
ClassNotFoundException / NoSuchMethodException at runtime (reflection, JSON serialization of DTOs) |
annotate with @RegisterForReflection (or @RegisterForReflection(targets = ...) on a holder class for third-party types), or put a reflection-config.json in src/main/resources and set quarkus.native.additional-build-args=-H:ReflectionConfigurationFiles=reflection-config.json |
| Missing resource files | quarkus.native.resources.includes=templates/** |
| Library not supporting native | look for a Quarkus extension, or choose another library |
| Class initialized at build time breaks | --initialize-at-run-time=... through quarkus.native.additional-build-args |
OutOfMemoryError during build |
raise container memory or quarkus.native.native-image-xmx |
| Dynamic proxies / serialization | register via annotations or extension |
@RegisterForReflection(targets = ExternalDto.class)
public record ProductDto(String name) {}
…
常见问题
什么是“原生可执行文件”?
它是直接编译到机器上运行的程序版本,不需要完整的 Java 环境。因此启动更快,通常也占用更少的资源。
为什么创建原生可执行文件很慢?
原生编译过程很复杂,需要大量内存和计算资源,因为它要分析所有代码进行优化,并使其能够在不依赖 Java 虚拟机(JVM)的情况下运行。
创建原生可执行文件时出现“ClassNotFoundException”错误该怎么办?
这通常意味着原生编译器不知道某个类需要被包含,或需要以特殊方式访问。你可以在代码中添加特定的注解,或创建一个配置文件告诉编译器来解决。
详情
作者的原始描述
Build Quarkus native executables (Mandrel/GraalVM), fix native failures with reflection registration, test the native binary, and produce container images and Kubernetes/OpenShift manifests. Use for native, Docker, Jib or Kubernetes work in a Quarkus project.
repo: github/awesome-copilot
热度
- GitHub 星标
- 40k
- 排名
- #7379
- 许可证
- MIT
- 更新时间
- 2026/10/15
评论
- …
同一仓库的更多技能
acquire-codebase-knowledge
40k帮你的智能体理解并编写现有代码项目的文档。它有助于新成员快速上手,或者快速了解项目架构。
acreadiness-assess
40k让你的智能体评估一个项目对 AI 的准备程度,并生成报告。它有助于了解项目在使用 AI 工具方面的准备情况。
acreadiness-generate-instructions
40k帮你的智能体根据评估结果编写 AI 工具的指令文件。它有助于改善 AI 与代码的交互方式,并弥补已发现的不足。
acreadiness-policy
40k让你的智能体协助制定或应用 AI 项目评估的政策。它有助于规范项目的评估方式,并确保合规。