Java -jar运行jar包时可添加参数

1、 -jar 参数

说明: 指定要执行的 JAR 文件。

示例:java -jar spring-boot-helloworld.jar

2、-D 参数

说明;设置系统属性,在代码中可以通过 System.getProperty("propertyName")获取,也可以通过@Value注解获取

示例:java -jar -Dproper.name=properValue spring-boot-helloworld.jar

3、-X 参数

说明: 设置 JVM 参数

示例:java -jar -Xmx512m spring-boot-helloworld.jar

4、--spring.profiles.active 参数

说明:指定使用Spring 配置文件中的特定 Profile,用于切换配置文件

示例:java -jar spring-boot-helloworld.jar --spring.profiles.active=8081

5、--spring.config.name 和 --spring.config.location 参数

说明:

  • --spring.config.location 参数用于指定 Spring Boot 应用加载配置文件的位置。默认情况下,Spring Boot 会从特定的默认位置加载配置文件,使用该参数可以让你灵活地指定自定义的配置文件路径
  • --spring.config.name 参数用于指定 Spring Boot 应用要加载的配置文件的名称。默认情况下,Spring Boot 会尝试加载名为 application 的配置文件,如 application.properties 或 application.yml。通过这个参数,你可以自定义配置文件的名称。

示例:java -jar spring-boot-helloworld.jar --spring.config.name=myapplication --spring.config.location=./config/

6、main方法启动参数

说明:在 java -jar 命令后直接列出的参数被传递给应用程序。可以在应用程序的 public static void main(String\[\] args) 方法中使用 args 数组获取这些参数。

示例:java -jar spring-boot-helloworld.jar arg1 arg2 arg3

相关推荐
罗超驿几秒前
18.Web API 实战:元素与表单属性的获取和修改
开发语言·前端·javascript
无风听海5 分钟前
JSON Web Token(JWT)完全指南
java·前端·json
被子你放开我31 分钟前
CRMEB PHP多商户升级4.0太麻烦了
开发语言·php
阿里嘎多学长32 分钟前
2026-06-01 GitHub 热点项目精选
开发语言·程序员·github·代码托管
JAVA社区1 小时前
Java高级全套教程(十一)—— Kubernetes 超详细企业级实战详解
java·运维·微服务·容器·面试·kubernetes
醒醒该学习了!1 小时前
Anaconda安装教程+第一个python例子
开发语言·python
在繁华处2 小时前
Java从零到熟练(九):并发编程基础
java·开发语言
木头程序员2 小时前
SSM框架学习笔记
java·开发语言·mysql·spring·maven
李白你好2 小时前
页面资产梳理 · 技术指纹识别 · Spring 端点探测
java·后端·spring