Tm0h 2023-04-15 01:47 采纳率: 100%
浏览 25
已结题

native-image-maven-plugin

先上POM.XML

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>test</groupId>
    <artifactId>test</artifactId>
    <version>1.0</version>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>3.0.4</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>

    <properties>
        <maven.compiler.source>17</maven.compiler.source>
        <maven.compiler.target>17</maven.compiler.target>
        <graalvm.version>22.3.1</graalvm.version>
        <java.version>17</java.version>
        <project.build.sourceEncoding>GBK</project.build.sourceEncoding>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.graalvm.sdk</groupId>
            <artifactId>graal-sdk</artifactId>
            <version>22.3.1</version>
            <scope>provided</scope>
        </dependency>

        <dependency>
            <groupId>jxl</groupId>
            <artifactId>jxl</artifactId>
            <version>1.0</version>
            <scope>system</scope>
            <systemPath>${project.basedir}/lib/jxl-2.6.12.jar</systemPath>
        </dependency>

        <dependency>
            <groupId>com.oracle.substratevm</groupId>
            <artifactId>native-image-maven-plugin</artifactId>
            <version>19.2.1</version>
            <type>maven-plugin</type>
        </dependency>
    </dependencies>


    <!--build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <version>3.0.4</version>
                <configuration>
                    <includeSystemScope>true</includeSystemScope>
                </configuration>
                <executions>
                    <execution>
                        <goals>
                            <goal>repackage</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build-->

    <build>
        <plugins>
            <plugin>
                <groupId>com.oracle.substratevm</groupId>
                <artifactId>native-image-maven-plugin</artifactId>
                <version>19.2.1</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>native-image</goal>
                        </goals>
                        <phase>package</phase>
                    </execution>
                </executions>
                <configuration>

                    <skip>false</skip>
                    <imageName>graalvmMaven</imageName>
                    <mainClass>test</mainClass>
                    <buildArgs>
                        -no-fallback
                    </buildArgs>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>

问题遇到的现象和发生背景

最后在目录下mvn clean package发生错误
Failed to execute goal com.oracle.substratevm:native-image-maven-plugin:19.2.1:native-image (default) on project test: Execution default of goal com.oracle.substratevm:native-image-maven-plugin:19.2.1:native-image failed: An API incompatibility was encountered while executing com.oracle.substratevm:native-image-maven-plugin:19.2.1:native-image: java.lang.IllegalAccessError: class org.graalvm.compiler.serviceprovider.JavaVersionUtil (in unnamed module @0x6b64429e) cannot access class jdk.vm.ci.services.Services (in module jdk.internal.vm.ci) because module jdk.internal.vm.ci does not export jdk.vm.ci.services to unnamed module @0x6b64429e

操作环境、软件版本等信息

spring生成的jar可以正常跑
java -agentlib:native-image-agent=config-output-dir=META-INF/native-image -jar
target目录下生成一个META-INF的文件夹,这个文件夹中包含的内容就是使用跟踪代理生成的反射配置。
这些都可以跑,没问题

尝试过的解决方法

class org.graalvm.compiler.serviceprovider.JavaVersionUtil cannot access class jdk.vm.ci.services.Services这个不知道怎么办了
%JAVA_HOME%指向的是graalvm的地址:
C:\Program Files\Java\graalvm-ee-java17-22.3.1

因为参照的Demo是用的

<groupId>org.graalvm.nativeimage</groupId>
    <artifactId>native-image-maven-plugin</artifactId>
    <version>21.2.0</version>

但阿里云的仓库没有,所以用了阿里云的

<groupId>com.oracle.substratevm</groupId>
                <artifactId>native-image-maven-plugin</artifactId>
                <version>19.2.1</version>
我想要达到的结果

能正常打包就好

  • 写回答

1条回答 默认 最新

  • 社区专家-Monster-XH 2023-04-15 16:36
    关注

    基于Monster 组和GPT的调写:
    可能是因为 native-image-maven-plugin 版本与 GraalVM 版本不兼容导致的。建议更新 native-image-maven-plugin 版本至 21.2.0 或更高版本,因为在 POM.xml 中使用的版本是 19.2.1,而且它也是一个较旧的版本。

    可以将以下内容添加到 中:

    <plugin>
        <groupId>org.graalvm.nativeimage</groupId>
        <artifactId>native-image-maven-plugin</artifactId>
        <version>21.2.0</version>
        <executions>
            <execution>
                <goals>
                    <goal>native-image</goal>
                </goals>
                <phase>package</phase>
            </execution>
        </executions>
        <configuration>
            <mainClass>test</mainClass>
        </configuration>
    </plugin>
    
    
    

    同时,如果想继续使用 com.oracle.substratevm:native-image-maven-plugin,可以尝试升级 GraalVM 到 21.2.0 或更高版本,因为这个插件的版本可能不支持所使用的 GraalVM 版本。

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

问题事件

  • 系统已结题 4月25日
  • 已采纳回答 4月17日
  • 修改了问题 4月15日
  • 创建了问题 4月15日

悬赏问题

  • ¥20 机器学习能否像多层线性模型一样处理嵌套数据
  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效