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

相关推荐
wno70424 分钟前
Centos下PostgreSQL安装部署详细步骤
java·数据库·spring boot
wuxianda10301 小时前
Swift 项目用 Xcode 脚手架起步:默认工程结构和依赖组合为什么会被识别成同源
开发语言·xcode·swift·4.3a·appstore审核
nice_lcj5201 小时前
【从零理解计算机网络 · 04】TCP 三次握手:为什么恰好是三次
java·后端·tcp/ip·计算机网络·面试·tcp·三次握手
ShineWinsu1 小时前
对于Qt:QVBoxLayout常见属性以及方法的解析
开发语言·数据库·c++·qt·gui·客户端·布局管理器
Sarvartha1 小时前
反射综合案例:SQL 语句生成
java·开发语言
Resean022312 小时前
Spring 源码分析(二)配置类的解析与扫描
java·后端·spring
小毛球.12 小时前
第 3 篇:IDEA 最新版下载与完整安装教程(Mac)
java·macos·intellij-idea·idea
ShineWinsu12 小时前
对于Qt:QFormLayout常见属性以及方法的解析
开发语言·c++·qt·面试·客户端·表单·qformlayout
Misnearch13 小时前
ScheduledExecutorService
java·线程池
ashiho14 小时前
【LeetCode hot 100】3. 无重复字符的最长子串 (三种解法)
java·数据结构·后端·算法·leetcode·滑动窗口