IntelliJ-使用args的Java Gradle运行/调试 [英] IntelliJ - Java Gradle Run/Debug with args

查看:118
本文介绍了IntelliJ-使用args的Java Gradle运行/调试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用Gradle的Spring应用程序,并使用bootRun任务运行/调试它. 这将使用main方法查找该类.

I have a Spring application with Gradle and I run/debug it with bootRun task. This looks for the class with main method.

但是有时候我必须通过main(String[] args)传递一个参数.

But sometimes I have to pass an argument for it, through main(String[] args).

如何从运行/调试"对话框中进行操作?我尝试了VM选项和参数,但是当断点到达args时,它为空.

How can I do it from Run/Debug dialog? I tried VM options and Arguments, but when breakpoint get at args, it's empty.

推荐答案

Spring Boot 文档中的命令行参数进行了描述,将其传递给bootRun任务为:

As Command-Line Arguments in Spring Boot document describes, pass it for bootRun task as:

-Pargs=<arg1>,<arg2>

build.gradle:

bootRun {
  if (project.hasProperty('args')) {
      args project.args.split(',')
  }
}

这篇关于IntelliJ-使用args的Java Gradle运行/调试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆