You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Docker容器中Java VM参数--add-opens配置失效问题咨询

问题分析与解决方案

你的问题出在Java VM参数的位置错误:--add-opens java.base/java.lang=ALL-UNNAMED被放在了engine.jar之后,这时候它会被当作Spring Boot应用的命令行参数,而非JVM的启动参数。Java虚拟机参数必须放在-jar选项的前面,才能被JVM正确解析。

修改后的Docker配置

# Use a Java runtime as the base image
FROM openjdk:21-slim-buster

VOLUME /tmp

# Copy the built JAR file into the container
ADD build/libs/engine.jar engine.jar

# Expose the default port for the app
EXPOSE 8080

# Start the app when the container launches
ENTRYPOINT ["java", "--add-opens java.base/java.lang=ALL-UNNAMED", "-jar", "engine.jar", "--spring.config.additional-location=file:/engine-configuration.yml"]

关键说明

  • 所有Java VM参数(比如--add-opens、-Xmx、-D开头的系统属性等)都需要放在-jar之前,确保JVM在加载JAR包前就读取这些配置。
  • 应用程序的参数(比如Spring Boot的--spring.config.additional-location)则放在JAR文件路径之后,会被应用本身接收处理。

内容的提问来源于stack exchange,提问作者Peter Penzov

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.28 16:55:55