【问题标题】:Spring Boot native:compile with multi module Maven buildSpring Boot native:使用多模块 Maven 构建进行编译
【发布时间】:2022-12-17 12:45:38
【问题描述】:

我尝试为具有多个 Maven 模块的 Spring Boot 3.0 应用程序编译 GraalVM Native Image。

模块结构如下:

heroes-parent
|- heroes-backend
|- heroes-frontend
|- heroes-webapp

每个子目录是父目录的一个模块

pom.xml 提取:

  <modules>
    <module>heroes-backend</module>
    <module>heroes-frontend</module>
    <module>heroes-webapp</module>
  </modules>

当我尝试使用(参见Spring Boot docs)构建应用程序时:

mvn -Pnative native:compile

它错误(因为父级没有类):

[ERROR] Failed to execute goal org.graalvm.buildtools:native-maven-plugin:0.9.18:compile (default-cli) on project heroes-parent: Image classpath is empty. Check if your classpath configuration is correct. -> [Help 1]

所以,我尝试先用mvn install构建整个应用程序,然后只用native:compile构建应用程序heroes-webapp

mvn install 
cd heroes-webapp
mvn -Pnative native:compile

但这失败并出现以下错误:

[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  14.047 s
[INFO] Finished at: 2022-12-12T16:26:20+01:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.springframework.boot:spring-boot-maven-plugin:3.0.0:process-aot (process-aot) on project heroes-webapp: Unable to compile generated source
[ERROR] cannot access heroes.WeblateProperties
[ERROR]   bad class file: /home/koc/git/work/koc/angular-spring-heroes/heroes-webapp/target/classes/heroes/WeblateProperties.class
[ERROR]     unable to access file: java.nio.file.NoSuchFileException: /home/koc/git/work/koc/angular-spring-heroes/heroes-webapp/target/classes/heroes/WeblateProperties.class
[ERROR]     Please remove or make sure it appears in the correct subdirectory of the classpath. /home/koc/git/work/koc/angular-spring-heroes/heroes-webapp/target/spring-aot/main/sources/heroes/WeblateProperties__BeanDefinitions.java 15:25
[ERROR] cannot access heroes.MainController
[ERROR]   bad class file: /home/koc/git/work/koc/angular-spring-heroes/heroes-webapp/target/classes/heroes/MainController.class
[ERROR]     unable to access file: java.nio.file.NoSuchFileException: /home/koc/git/work/koc/angular-spring-heroes/heroes-webapp/target/classes/heroes/MainController.class
[ERROR]     Please remove or make sure it appears in the correct subdirectory of the classpath. /home/koc/git/work/koc/angular-spring-heroes/heroes-webapp/target/spring-aot/main/sources/heroes/MainController__BeanDefinitions.java 15:25
[ERROR] cannot access heroes.HeroesApplication
[ERROR]   bad class file: /home/koc/git/work/koc/angular-spring-heroes/heroes-webapp/target/classes/heroes/HeroesApplication.class
[ERROR]     unable to access file: java.nio.file.NoSuchFileException: /home/koc/git/work/koc/angular-spring-heroes/heroes-webapp/target/classes/heroes/HeroesApplication.class
[ERROR]     Please remove or make sure it appears in the correct subdirectory of the classpath. /home/koc/git/work/koc/angular-spring-heroes/heroes-webapp/target/spring-aot/main/sources/heroes/HeroesApplication__BeanDefinitions.java 18:25

你可以找到source code for the whole application on GitHub

有没有办法用 Maven 多模块 Spring Boot 3 应用程序构建本机图像?

【问题讨论】:

    标签: java spring spring-boot maven graalvm-native-image


    【解决方案1】:

    我发现了问题。 Visual Studio Code 已打开,项目已使用 Extension Pack for Java 加载。这是在 Maven 构建它们时删除了类,这导致了上述错误。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-04-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-09-17
      • 1970-01-01
      相关资源
      最近更新 更多