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

相关推荐
super凹凸曼几秒前
分享一个把你的API快速升级为MCP规范的方案,可在线体验
java·后端·开源
矛取矛求10 分钟前
STL C++详解——priority_queue的使用和模拟实现 堆的使用
开发语言·c++
howeres14 分钟前
Spring Boot 应用优雅关闭
java·spring boot
码上飞扬21 分钟前
用Java实现简易区块链:从零开始的探索
java·区块链·哈希算法
南汐以墨25 分钟前
Maven与Springboot创建
java·spring boot·maven
Non importa39 分钟前
【C++】新手入门指南(下)
java·开发语言·c++·算法·学习方法
创码小奇客41 分钟前
MongoDB 索引操作:数据世界的超速导航指南
java·mongodb·trae
秋野酱44 分钟前
基于javaweb的SpringBoot儿童爱心管理系统设计与实现(源码+文档+部署讲解)
java·spring boot·后端
头顶秃成一缕光1 小时前
TCP的三次握手和四次挥手
java·服务器·tcp/ip·软件工程
苏格拉没有底_coder1 小时前
【EasyPan】项目常见问题解答(自用&持续更新中…)
java