build-native-image-maven
Skill này làm gì
Skill này giúp nhà phát triển Java biến dự án Maven thành chương trình native khởi động nhanh. Skill dành cho các nhóm muốn ứng dụng Java nhẹ hơn và nhanh hơn.
Khi nào nên dùng
- ✓Khi bạn muốn build một ứng dụng Java thành GraalVM native image bằng Maven.
- ✓Khi bạn cần thêm native-maven-plugin vào file pom.xml.
- ✓Khi quá trình build native image lỗi và bạn cần giúp thu thập metadata hoặc sửa lỗi runtime.
Liên kết skill
https://github.com/oracle/graal/blob/master/docs/reference-manual/native-image/assets/skills/build-native-image-maven/SKILL.mdSao chép rồi dán vào AI của bạn (Claude, ChatGPT hoặc Cursor) và nhờ nó làm theo hướng dẫn.
Cách dùng
Cách dễ nhất: sao chép tin nhắn và dán vào AI của bạn. AI sẽ đọc skill và làm theo hướng dẫn.
Tin nhắn có sẵn để dán
Dành cho Claude Code, Codex hoặc Cursor: chạy lệnh trong thư mục dự án của bạn và skill sẽ được cài đặt.
Tải tệp SKILL.md về và thả vào thư mục skill của agent.
Ví dụ cách nhờ AI
“Thêm một profile native vào file pom.xml của Maven để tôi có thể build ứng dụng Java thành native image.”
5 skill mới mỗi tuần. Đọc chỉ 1 phút.
Cách hoạt động
Skill thêm một profile native với native-maven-plugin vào pom.xml, rồi build bằng Maven wrapper. Skill đặt JAVA_HOME trỏ tới GraalVM JDK để plugin tìm được công cụ native-image.
Nội dung kỹ thuật (SKILL.md gốc)
Lấy nguyên văn từ GitHub, do tác giả viết bằng tiếng Anh.
Maven Native Image Build
Prerequisites
- Set
JAVA_HOMEto a GraalVM JDK installation so the plugin can findnative-image. - Do not require
GRAALVM_HOMEin the normal case. Only mention it if the user already relies on it or their environment needs an explicit override. - Use Maven 3.6+.
Plugin Setup
Add the following to your pom.xml inside a native profile:
<profiles>
<profile>
<id>native</id>
<build>
<plugins>
<plugin>
<groupId>org.graalvm.buildtools</groupId>
<artifactId>native-maven-plugin</artifactId>
<version>0.11.1</version>
<extensions>true</extensions>
<executions>
<execution>
<id>build-native</id>
<goals>
<goal>compile-no-fork</goal>
</goals>
<phase>package</phase>
</execution>
<execution>
<id>test-native</id>
<goals>
<goal>test</goal>
</goals>
<phase>test</phase>
</execution>
</executions>
<configuration>
<mainClass>org.example.Main</mainClass>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>
Build and Run
./mvnw -Pnative package # Build native image → target/<imageName>
./target/myapp # Run the native executable
./mvnw -Pnative test # Build and run JUnit tests as a native image
./mvnw -Pnative -DskipTests package # Skip all tests
./mvnw -Pnative -DskipNativeTests package # Run JVM tests only, skip native
Plugin Not Resolving or Activating
- "Could not resolve artifact" — Ensure
mavenCentral()is in repositories and the version is correct. - "Could not find goal 'compile-no-fork'" — Verify
<extensions>true</extensions>is set on the plugin. - Build runs without native compilation — Check you are activating the profile:
./mvnw -Pnative package.
Build or Runtime Failures
For class initialization errors, linking issues, memory problems, or unexpected runtime behavior, see references/maven-plugin-options.md.
Missing Reachability Metadata
When native-image reports missing reflection, resources, serialization, or JNI entries, see references/reachability-metadata.md.
Native Testing
For nativeTest failures or setting up native JUnit tests, see references/testing.md.
Reference Files
| Topic | File |
|---|---|
| Plugin configuration options | references/maven-plugin-options.md |
| Missing reachability metadata | references/reachability-metadata.md |
| Native testing | references/testing.md |
Câu hỏi thường gặp
Cần phiên bản Maven nào?
Maven 3.6 trở lên.
Skill có dùng GRAALVM_HOME không?
Thường là không. Skill dựa vào JAVA_HOME, và chỉ nhắc tới GRAALVM_HOME nếu bạn đang dùng nó.
Có thể chạy test native không?
Có. Skill thiết lập một lần thực thi test-native cho các test JUnit native.
Chi tiết
Mô tả gốc của tác giả
Build GraalVM native images using the native-maven-plugin (org.graalvm.buildtools). Use this skill to build Java applications with Maven, configure pom.xml native image settings, run native tests, collect metadata, or resolve build or runtime issues.
repo: oracle/graal
Độ phổ biến
- Sao GitHub
- 22k
- Vị trí xếp hạng
- #10357
- Giấy phép
- —
- Cập nhật
- 2/11/2026
Bình luận
- …
Thêm skill từ kho mã này
build-native-image-gradle
22kGiúp agent của bạn build ứng dụng Java thành GraalVM native image nhanh bằng Gradle, và sửa các lỗi build hoặc runtime thường gặp.
building-native-image
22kHướng dẫn agent của bạn biến chương trình Java thành ứng dụng độc lập nhanh bằng GraalVM Native Image, và sửa các lỗi build hoặc runtime thường gặp.
Skill tương tự
api-connector-builder
280kGiúp agent của bạn xây dựng kết nối API mới theo đúng mẫu đã có, dùng khi bạn cần thêm một tích hợp mà không tạo cách làm mới.
api-design
280kGiúp agent của bạn thiết kế REST API theo các thực hành tốt nhất, hữu ích để định nghĩa cách API giao tiếp, hiển thị lỗi và tổ chức dữ liệu.
backend-patterns
280kGiúp agent của bạn với các mẫu kiến trúc phía máy chủ và tối ưu cơ sở dữ liệu, hữu ích khi xây dựng hoặc rà soát code chạy trên máy chủ.