我正在try 将我的Spring Boot项目编译为本机(下面的信息),但我遇到了以下错误:

[INFO]     [creator]     Build resources:
[INFO]     [creator]      - 9.77GB of memory (63.1% of 15.47GB system memory, determined at start)
[INFO]     [creator]      - 20 thread(s) (100.0% of 20 available processor(s), determined at start)
[INFO]     [creator]     Feb 29, 2024 9:02:02 AM org.springframework.data.jpa.repository.query.QueryEnhancerFactory <clinit>
[INFO]     [creator]     INFO: Hibernate is in classpath; If applicable, HQL parser will be used.
[INFO]     [creator]     SLF4J(W): No SLF4J providers were found.
[INFO]     [creator]     SLF4J(W): Defaulting to no-operation (NOP) logger implementation
[INFO]     [creator]     SLF4J(W): See https://www.slf4j.org/codes.html#noProviders for further details.
[INFO]     [creator]     [2/8] Performing analysis...  [*]                               (68.3s @ 5.50GB)
[INFO]     [creator]        55,295 reachable types   (92.0% of   60,129 total)
[INFO]     [creator]        87,563 reachable fields  (64.1% of  136,691 total)
[INFO]     [creator]       271,068 reachable methods (63.2% of  429,166 total)
[INFO]     [creator]        17,065 types, 2,896 fields, and 34,625 methods registered for reflection
[INFO]     [creator]     
[INFO]     [creator]     Error: Classes that should be initialized at run time got initialized during image building:
[INFO]     [creator]      ch.qos.logback.core.subst.Token was unintentionally initialized at build time. To see why ch.qos.logback.core.subst.Token got initialized use --trace-class-initialization=ch.qos.logback.core.subst.Token
[INFO]     [creator]     ch.qos.logback.core.joran.util.PropertySetter$1 was unintentionally initialized at build time. To see why ch.qos.logback.core.joran.util.PropertySetter$1 got initialized use --trace-class-initialization=ch.qos.logback.core.joran.util.PropertySetter$1
[INFO]     [creator]     ch.qos.logback.core.model.processor.ImplicitModelHandler$1 was unintentionally initialized at build time. To see why ch.qos.logback.core.model.processor.ImplicitModelHandler$1 got initialized use --trace-class-initialization=ch.qos.logback.core.model.processor.ImplicitModelHandler$1
[INFO]     [creator]     org.apache.logging.log4j.spi.Provider was unintentionally initialized at build time. To see why org.apache.logging.log4j.spi.Provider got initialized use --trace-class-initialization=org.apache.logging.log4j.spi.Provider
[INFO]     [creator]     org.apache.logging.log4j.util.LoaderUtil was unintentionally initialized at build time. To see why org.apache.logging.log4j.util.LoaderUtil got initialized use --trace-class-initialization=org.apache.logging.log4j.util.LoaderUtil
[INFO]     [creator]     org.apache.commons.logging.impl.Jdk14Logger was unintentionally initialized at build time. To see why org.apache.commons.logging.impl.Jdk14Logger got initialized use --trace-class-initialization=org.apache.commons.logging.impl.Jdk14Logger
[INFO]     [creator]     ch.qos.logback.classic.model.processor.LogbackClassicDefaultNestedComponentRules was unintentionally initialized at build time. To see why ch.qos.logback.classic.model.processor.LogbackClassicDefaultNestedComponentRules got initialized use --trace-class-initialization=ch.qos.logback.classic.model.processor.LogbackClassicDefaultNestedComponentRules
[INFO]     [creator]     org.apache.logging.log4j.spi.StandardLevel was unintentionally initialized at build time. To see why org.apache.logging.log4j.spi.StandardLevel got initialized use --trace-class-initialization=org.apache.logging.log4j.spi.StandardLevel
[INFO]     [creator]     org.apache.logging.log4j.util.Constants was unintentionally initialized at build time. To see why org.apache.logging.log4j.util.Constants got initialized use --trace-class-initialization=org.apache.logging.log4j.util.Constants
[INFO]     [creator]     org.apache.commons.logging.LogFactory was unintentionally initialized at build time. To see why org.apache.commons.logging.LogFactory got initialized use --trace-class-initialization=org.apache.commons.logging.LogFactory
[INFO]     [creator]     ch.qos.logback.core.rolling.helper.FileNamePattern was unintentionally initialized at build time. To see why ch.qos.logback.core.rolling.helper.FileNamePattern got initialized use --trace-class-initialization=ch.qos.logback.core.rolling.helper.FileNamePattern
[INFO]     [creator]     ch.qos.logback.core.rolling.helper.RollingCalendar was unintentionally initialized at build time. To see why ch.qos.logback.core.rolling.helper.RollingCalendar got initialized use --trace-class-initialization=ch.qos.logback.core.rolling.helper.RollingCalendar
[INFO]     [creator]     ch.qos.logback.core.util.FileSize was unintentionally initialized at build time. To see why ch.qos.logback.core.util.FileSize got initialized use --trace-class-initialization=ch.qos.logback.core.util.FileSize
[INFO]     [creator]     org.apache.logging.log4j.util.PropertySource$Util was unintentionally initialized at build time. To see why org.apache.logging.log4j.util.PropertySource$Util got initialized use --trace-class-initialization=org.apache.logging.log4j.util.PropertySource$Util
[INFO]     [creator]     org.apache.logging.log4j.util.OsgiServiceLocator was unintentionally initialized at build time. To see why org.apache.logging.log4j.util.OsgiServiceLocator got initialized use --trace-class-initialization=org.apache.logging.log4j.util.OsgiServiceLocator
[INFO]     [creator]     ch.qos.logback.core.util.SimpleInvocationGate was unintentionally initialized at build time. To see why ch.qos.logback.core.util.SimpleInvocationGate got initialized use --trace-class-initialization=ch.qos.logback.core.util.SimpleInvocationGate
[INFO]     [creator]     ch.qos.logback.core.pattern.parser.Parser was unintentionally initialized at build time. To see why ch.qos.logback.core.pattern.parser.Parser got initialized use --trace-class-initialization=ch.qos.logback.core.pattern.parser.Parser
[INFO]     [creator]     ch.qos.logback.core.util.Duration was unintentionally initialized at build time. To see why ch.qos.logback.core.util.Duration got initialized use --trace-class-initialization=ch.qos.logback.core.util.Duration
[INFO]     [creator]     org.apache.logging.log4j.spi.AbstractLogger was unintentionally initialized at build time. To see why org.apache.logging.log4j.spi.AbstractLogger got initialized use --trace-class-initialization=org.apache.logging.log4j.spi.AbstractLogger
[INFO]     [creator]     ch.qos.logback.core.model.processor.DefaultProcessor$1 was unintentionally initialized at build time. To see why ch.qos.logback.core.model.processor.DefaultProcessor$1 got initialized use --trace-class-initialization=ch.qos.logback.core.model.processor.DefaultProcessor$1
[INFO]     [creator]     ch.qos.logback.core.subst.Parser$1 was unintentionally initialized at build time. To see why ch.qos.logback.core.subst.Parser$1 got initialized use --trace-class-initialization=ch.qos.logback.core.subst.Parser$1
[INFO]     [creator]     ch.qos.logback.core.subst.NodeToStringTransformer$1 was unintentionally initialized at build time. To see why ch.qos.logback.core.subst.NodeToStringTransformer$1 got initialized use --trace-class-initialization=ch.qos.logback.core.subst.NodeToStringTransformer$1
[INFO]     [creator]     org.apache.logging.log4j.status.StatusLogger was unintentionally initialized at build time. To see why org.apache.logging.log4j.status.StatusLogger got initialized use --trace-class-initialization=org.apache.logging.log4j.status.StatusLogger
[INFO]     [creator]     ch.qos.logback.core.CoreConstants was unintentionally initialized at build time. To see why ch.qos.logback.core.CoreConstants got initialized use --trace-class-initialization=ch.qos.logback.core.CoreConstants
[INFO]     [creator]     org.slf4j.LoggerFactory was unintentionally initialized at build time. To see why org.slf4j.LoggerFactory got initialized use --trace-class-initialization=org.slf4j.LoggerFactory
[INFO]     [creator]     org.slf4j.MarkerFactory was unintentionally initialized at build time. To see why org.slf4j.MarkerFactory got initialized use --trace-class-initialization=org.slf4j.MarkerFactory
[INFO]     [creator]     ch.qos.logback.core.status.InfoStatus was unintentionally initialized at build time. To see why ch.qos.logback.core.status.InfoStatus got initialized use --trace-class-initialization=ch.qos.logback.core.status.InfoStatus
[INFO]     [creator]     ch.qos.logback.core.rolling.helper.Compressor$1 was unintentionally initialized at build time. To see why ch.qos.logback.core.rolling.helper.Compressor$1 got initialized use --trace-class-initialization=ch.qos.logback.core.rolling.helper.Compressor$1
[INFO]     [creator]     ch.qos.logback.core.rolling.helper.RollingCalendar$1 was unintentionally initialized at build time. To see why ch.qos.logback.core.rolling.helper.RollingCalendar$1 got initialized use --trace-class-initialization=ch.qos.logback.core.rolling.helper.RollingCalendar$1
[INFO]     [creator]     ch.qos.logback.classic.PatternLayout was unintentionally initialized at build time. To see why ch.qos.logback.classic.PatternLayout got initialized use --trace-class-initialization=ch.qos.logback.classic.PatternLayout
[INFO]     [creator]     org.apache.logging.log4j.Level was unintentionally initialized at build time. To see why org.apache.logging.log4j.Level got initialized use --trace-class-initialization=org.apache.logging.log4j.Level
[INFO]     [creator]     org.apache.logging.log4j.util.Strings was unintentionally initialized at build time. To see why org.apache.logging.log4j.util.Strings got initialized use --trace-class-initialization=org.apache.logging.log4j.util.Strings
[INFO]     [creator]     org.apache.logging.slf4j.SLF4JProvider was unintentionally initialized at build time. To see why org.apache.logging.slf4j.SLF4JProvider got initialized use --trace-class-initialization=org.apache.logging.slf4j.SLF4JProvider
[INFO]     [creator]     ch.qos.logback.core.status.WarnStatus was unintentionally initialized at build time. To see why ch.qos.logback.core.status.WarnStatus got initialized use --trace-class-initialization=ch.qos.logback.core.status.WarnStatus
[INFO]     [creator]     ch.qos.logback.classic.Logger was unintentionally initialized at build time. To see why ch.qos.logback.classic.Logger got initialized use --trace-class-initialization=ch.qos.logback.classic.Logger
[INFO]     [creator]     ch.qos.logback.core.model.processor.ChainedModelFilter$1 was unintentionally initialized at build time. To see why ch.qos.logback.core.model.processor.ChainedModelFilter$1 got initialized use --trace-class-initialization=ch.qos.logback.core.model.processor.ChainedModelFilter$1
[INFO]     [creator]     ch.qos.logback.classic.Level was unintentionally initialized at build time. To see why ch.qos.logback.classic.Level got initialized use --trace-class-initialization=ch.qos.logback.classic.Level
[INFO]     [creator]     ch.qos.logback.core.status.StatusBase was unintentionally initialized at build time. To see why ch.qos.logback.core.status.StatusBase got initialized use --trace-class-initialization=ch.qos.logback.core.status.StatusBase
[INFO]     [creator]     org.apache.logging.log4j.util.PropertiesUtil was unintentionally initialized at build time. To see why org.apache.logging.log4j.util.PropertiesUtil got initialized use --trace-class-initialization=org.apache.logging.log4j.util.PropertiesUtil
[INFO]     [creator]     org.apache.logging.log4j.simple.SimpleLogger was unintentionally initialized at build time. To see why org.apache.logging.log4j.simple.SimpleLogger got initialized use --trace-class-initialization=org.apache.logging.log4j.simple.SimpleLogger
[INFO]     [creator]     ch.qos.logback.core.util.Loader was unintentionally initialized at build time. To see why ch.qos.logback.core.util.Loader got initialized use --trace-class-initialization=ch.qos.logback.core.util.Loader
[INFO]     [creator]     To see how the classes got initialized, use --trace-class-initialization=ch.qos.logback.core.subst.Token,ch.qos.logback.core.joran.util.PropertySetter$1,ch.qos.logback.core.model.processor.ImplicitModelHandler$1,org.apache.logging.log4j.spi.Provider,org.apache.logging.log4j.util.LoaderUtil,org.apache.commons.logging.impl.Jdk14Logger,ch.qos.logback.classic.model.processor.LogbackClassicDefaultNestedComponentRules,org.apache.logging.log4j.spi.StandardLevel,org.apache.logging.log4j.util.Constants,org.apache.commons.logging.LogFactory,ch.qos.logback.core.rolling.helper.FileNamePattern,ch.qos.logback.core.rolling.helper.RollingCalendar,ch.qos.logback.core.util.FileSize,org.apache.logging.log4j.util.PropertySource$Util,org.apache.logging.log4j.util.OsgiServiceLocator,ch.qos.logback.core.util.SimpleInvocationGate,ch.qos.logback.core.pattern.parser.Parser,ch.qos.logback.core.util.Duration,org.apache.logging.log4j.spi.AbstractLogger,ch.qos.logback.core.model.processor.DefaultProcessor$1,ch.qos.logback.core.subst.Parser$1,ch.qos.logback.core.subst.NodeToStringTransformer$1,org.apache.logging.log4j.status.StatusLogger,ch.qos.logback.core.CoreConstants,org.slf4j.LoggerFactory,org.slf4j.MarkerFactory,ch.qos.logback.core.status.InfoStatus,ch.qos.logback.core.rolling.helper.Compressor$1,ch.qos.logback.core.rolling.helper.RollingCalendar$1,ch.qos.logback.classic.PatternLayout,org.apache.logging.log4j.Level,org.apache.logging.log4j.util.Strings,org.apache.logging.slf4j.SLF4JProvider,ch.qos.logback.core.status.WarnStatus,ch.qos.logback.classic.Logger,ch.qos.logback.core.model.processor.ChainedModelFilter$1,ch.qos.logback.classic.Level,ch.qos.logback.core.status.StatusBase,org.apache.logging.log4j.util.PropertiesUtil,org.apache.logging.log4j.simple.SimpleLogger,ch.qos.logback.core.util.Loader
[INFO]     [creator]     --------------------------------------------------------------------------------
[INFO]     [creator]       18.5s (23.7% of total time) in 147 GCs | Peak RSS: 8.84GB | CPU load: 13.21
[INFO]     [creator]     ================================================================================
[INFO]     [creator]     Finished generating 'io.xhub.cmi.payyou.eservice.StarterApplication' in 1m 17s.
[INFO]     [creator]     unable to invoke layer creator
[INFO]     [creator]     unable to contribute native-image layer
[INFO]     [creator]     error running build
[INFO]     [creator]     exit status 1
[INFO]     [creator]     ERROR: failed to build: exit status 1
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  04:05 min
[INFO] Finished at: 2024-02-29T10:02:53+01:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.springframework.boot:spring-boot-maven-plugin:3.2.3:build-image (default-cli) on project e-service: Execution default-cli of goal org.springframework.boot:spring-boot-maven-plugin:3.2.3:build-image failed: Builder lifecycle 'creator' failed with status code 51 -> [Help 1]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.

我正在使用这个插件配置,这是我在Stack Overflow和GitHub问题上看到的答案所建议的:

<plugin>
    <groupId>org.graalvm.buildtools</groupId>
    <artifactId>native-maven-plugin</artifactId>
    <configuration>
        <buildArgs combine.children="append">
            <buildArg>
                --initialize-at-build-time=ch.qos.logback.core.subst.Token,ch.qos.logback.core.util.SimpleInvocationGate,ch.qos.logback.core.pattern.parser.Parser,ch.qos.logback.classic.model.processor.LogbackClassicDefaultNestedComponentRules,org.apache.logging.log4j.util.Constants,org.apache.commons.logging.impl.Jdk14Logger,org.apache.logging.log4j.util.PropertySource$Util,org.apache.logging.log4j.util.Strings,org.slf4j.MarkerFactory,ch.qos.logback.core.model.processor.ImplicitModelHandler$1,org.apache.logging.log4j.spi.StandardLevel,ch.qos.logback.classic.PatternLayout,org.apache.logging.log4j.util.PropertiesUtil,ch.qos.logback.core.status.InfoStatus,org.slf4j.LoggerFactory,ch.qos.logback.core.model.processor.ChainedModelFilter$1,org.apache.logging.log4j.spi.AbstractLogger,org.apache.logging.log4j.util.OsgiServiceLocator,ch.qos.logback.core.joran.util.PropertySetter$1,org.apache.logging.log4j.Level,ch.qos.logback.classic.Level,ch.qos.logback.core.model.processor.DefaultProcessor$1,ch.qos.logback.core.rolling.helper.FileNamePattern,ch.qos.logback.core.status.StatusBase,ch.qos.logback.classic.Logger,org.apache.logging.log4j.status.StatusLogger,org.apache.logging.slf4j.SLF4JProvider,ch.qos.logback.core.util.FileSize,org.apache.logging.log4j.util.LoaderUtil,ch.qos.logback.core.subst.Parser$1,ch.qos.logback.core.rolling.helper.Compressor$1,ch.qos.logback.core.rolling.helper.RollingCalendar,ch.qos.logback.core.status.WarnStatus,org.apache.logging.log4j.spi.Provider,org.apache.commons.logging.LogFactory,ch.qos.logback.core.subst.NodeToStringTransformer$1,ch.qos.logback.core.rolling.helper.RollingCalendar$1,ch.qos.logback.core.CoreConstants,org.apache.logging.log4j.simple.SimpleLogger,ch.qos.logback.core.util.Duration,ch.qos.logback.core.util.Loader
            </buildArg>
        </buildArgs>
    </configuration>
</plugin>

但不幸的是,Arg似乎被忽视了.

请注意,我已经try 了environmentbuildArgs.arg和其他配置的几种组合,但都没有效果.

我正在使用:

  • 弹簧船3.2.3
  • Java 21

构建时,创建者下载并使用此图像:

[INFO]     [creator]         Using Java version 21 extracted from MANIFEST.MF
[INFO]     [creator]       BellSoft Liberica NIK 21.0.2: Contributing to layer
[INFO]     [creator]         Downloading from https://download.bell-sw.com/vm/23.1.2/bellsoft-liberica-vm-core-openjdk21.0.2+14-23.1.2+1-linux-amd64.tar.gz
[INFO]     [creator]         Verifying checksum
[INFO]     [creator]         Expanding to /layers/paketo-buildpacks_bellsoft-liberica/native-image-svm

This issue看起来很相似,但我的类路径中没有任何snowflake依赖项.

我如何将--initialize-at-build-time和/或--trace-class-initialization传递到我的Maven版本?

我按照the docs使用以下命令:

mvn -Pnative spring-boot:build-image

推荐答案

您使用构建包从应用程序构建本机映像,因此Native Image Maven插件不会参与映像的编译.然而,它确实提供了一些元数据,这些元数据被提供给图像的构建,所以你应该在你的pom.xml中保留它的声明.

如果引用README for the native image buildpack,您将看到BP_NATIVE_IMAGE_BUILD_ARGUMENTS环境变量允许您将参数传递给native-image命令:

要直接传递给本机映像命令的参数.这些参数必须有效且格式正确,否则native-image命令将失败.

如果你参考Spring Boot的Maven插件的文档,它是describes how to pass environment variables to the builder and its buildpacks.在你的例子中,你可以这样配置:

<plugin>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-maven-plugin</artifactId>
    <configuration>
        <image>
            <env>
                <BP_NATIVE_IMAGE_BUILD_ARGUMENTS>--trace-class-initialization=…</BP_NATIVE_IMAGE_BUILD_ARGUMENTS>
            </env>
        </image>
    </configuration>
</plugin>

Java相关问答推荐

Java取消任务运行Oracle查询通过JDBC—连接中断,因为SQLSTATE(08006),错误代码(17002)IO错误:套接字读取中断

Java函数式编程中的双值单值映射

JavaFX Maven Assembly插件一直打包到错误的JDK版本

Java:使用Class.cast()将对象转换为原始数组

使用Spring和ActiveMQ的侦听器方法引发属性名称不能重复为空警告

带错误BER验证的itext8签名返回pdf

如何只修改父类ChroniclerView位置0处的第一个嵌套ChroniclerView(child)元素?

Java连接池无法正常工作

如何用内置Java从JavaFX应用程序中生成.exe文件?

Spring Boot中的应用程序.properties文件中未使用的属性

IntelliJ IDEA中的JavaFX应用程序无法在资源中找到CSS文件

在Java中将.GRF转换为图像文件

Maven-Dependency-Plugin 3.6.+开始查找在依赖关系:分析目标期间找到的新的使用的未声明依赖关系

模拟JUnit未检测到返回字符串的方法的任何声纳覆盖

如何使用stream.allMatch()为空流返回false?

Eureka客户端无法使用用户/通行证注册到Eureka服务器

在外部类和内部类之间,当调用外部类内部或外部的主方法时,它们的静态初始化程序的运行顺序不同

JAVA 正则表达式识别字符串string或字符串内的字符char

如何使用 JDBC 更改 Postgres Enum 类型

Java ModbusRTU写寄存器