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

相关推荐
lly20240614 分钟前
Bootstrap 警告框
开发语言
2601_949146531 小时前
C语言语音通知接口接入教程:如何使用C语言直接调用语音预警API
c语言·开发语言
曹牧1 小时前
Spring Boot:如何测试Java Controller中的POST请求?
java·开发语言
KYGALYX1 小时前
服务异步通信
开发语言·后端·微服务·ruby
zmzb01031 小时前
C++课后习题训练记录Day98
开发语言·c++
爬山算法2 小时前
Hibernate(90)如何在故障注入测试中使用Hibernate?
java·后端·hibernate
kfyty7252 小时前
集成 spring-ai 2.x 实践中遇到的一些问题及解决方案
java·人工智能·spring-ai
猫头虎2 小时前
如何排查并解决项目启动时报错Error encountered while processing: java.io.IOException: closed 的问题
java·开发语言·jvm·spring boot·python·开源·maven
李少兄2 小时前
在 IntelliJ IDEA 中修改 Git 远程仓库地址
java·git·intellij-idea
YUJIANYUE2 小时前
PHP纹路验证码
开发语言·php