Java 如何让 IntelliJ 提示我输入命令行参数
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/20689273/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to make IntelliJ prompt me for command line arguments
提问by Carl Karawani
In Eclipse, you can provide the program argument ${string_prompt}
in your run configuration to have it prompt for the command line arguments.
在 Eclipse 中,您可以${string_prompt}
在运行配置中提供程序参数以提示输入命令行参数。
Is there a way to do this in IntelliJ?
有没有办法在 IntelliJ 中做到这一点?
回答by Micha? Rybak
Edit:
编辑:
This may be a bug in IDEA, the solution that I first posted (you can see it below) causes Intellij to hang after entering parameter.
这可能是IDEA中的一个bug,我第一次贴出的解决方案(你可以在下面看到它)导致Intellij在输入参数后挂起。
I couldn't come up with a solution to this, but here's a little trick: you can scroll to the very bottom of Run/Debug configuration screen and in "Before launch" section check a checkbox saying "Show this page".
我想不出一个解决方案,但这里有一个小技巧:您可以滚动到运行/调试配置屏幕的最底部,并在“启动前”部分选中“显示此页面”复选框。
From now on you'll be automatically shown configuration screenwhen you choose to Run/Debug your application and there you can enter any parameters you want... It's not that comfortable, but at least a little bitmore automatized.
从现在开始,当您选择运行/调试您的应用程序时,您将自动看到配置屏幕,您可以在那里输入您想要的任何参数......这不是那么舒服,但至少自动化了一点。
Previous answer:
上一个答案:
This is a bit more complicated with Intellij:
这对于 Intellij 来说有点复杂:
- go to
Settings -> External Tools -> Add (green plus)
- in
Parameters
line clickInsert macro -> Prompt
(you can simply type in$Prompt$
as well) - save settings
- go to
Run -> Edit Configurations...
- in
Before Launch
section chooseRun External Tool
and select tool that you've created
- 去
Settings -> External Tools -> Add (green plus)
- 在
Parameters
线路点击Insert macro -> Prompt
(你可以简单地键入$Prompt$
为好) - 保存设置
- 去
Run -> Edit Configurations...
- 在
Before Launch
部分选择Run External Tool
并选择您创建的工具
That should suffice (works in IDEA 12.1.6).
这应该足够了(适用于 IDEA 12.1.6)。
回答by Grodriguez
Starting from versions 2018.3 and 2019.1, IntelliJ now supports macros in Run configurations. You can use $Prompt$
anywhere in the VM Options, Program arguments, etc. fields, and it will behave just like ${string_prompt}
in Eclipse -- it will prompt you for parameters when the configuration is run.
从 2018.3 和 2019.1 版本开始,IntelliJ 现在支持运行配置中的宏。您可以$Prompt$
在 VM 选项、程序参数等字段中的任何位置使用,它的行为就像${string_prompt}
在 Eclipse 中一样——它会在配置运行时提示您输入参数。