Chuyển đến nội dung
Skillpedia
API và máy chủ (backend)22k · #10357

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.md

Sao 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

Hãy dùng skill này để giúp tôi: https://github.com/oracle/graal/blob/master/docs/reference-manual/native-image/assets/skills/build-native-image-maven/SKILL.md Đọc tệp SKILL.md tại liên kết đó và làm theo hướng dẫn cho việc của tôi.
Bạn muốn AI tự tìm những skill như thế này?Cài MCP Skillpedia miễn phí: chỉ một dòng, và AI sẽ tìm trong 15.000+ skill trước mỗi việc.Cài đặt trong 1 phút →

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_HOME to a GraalVM JDK installation so the plugin can find native-image.
  • Do not require GRAALVM_HOME in 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

Skill này có hữu ích không?

0

Đăng nhập để bình chọn.

Bình luận

  • …

Thêm skill từ kho mã này

Skill tương tự