我通常通过运行配置在Eclipse中输入命令行参数。但是我不知道如何在IntelliJ IDEA中实现同样的任务。


当前回答

在“运行”菜单上有一个“编辑配置”项,在工具栏上两个绿色“运行”和“调试”箭头左边的下拉菜单上。在该面板中,使用左上角的“+”按钮创建配置,然后可以选择包含main()的Class,添加VM参数和命令行参数,指定工作目录和任何环境变量。

还有其他选项:代码覆盖率、日志记录、构建、JRE等。

其他回答

在运行“OSX 10.11.3”的MacBook Air上:

CTRL + Alt + r e 输入 程序参数: 编写命令行参数(如果有多个参数,则每个项之间有空格) 输入

点击“编辑配置…”从工具栏顶部 在弹出窗口中,确保“环境”部分展开(通过单击下拉箭头) 应用程序的命令行参数应该进入“程序参数”字段

我有一个类Test:

然后。转到配置运行类Test:

步骤1:添加应用

步骤2:

您可以在“程序参数”文本框中输入参数。

只需左键单击当前配置(我的是主),并选择编辑配置,

然后在输入字段中,程序参数输入您的值,就像在控制台中一样,单击OK。

自IntelliJ IDEA 2021年以来,我对这个问题添加了更新的答案。

Select Edit Configuration from the toolbar (or under the Run menu): Picture of new location of edit configuration box You now have to click on the Modify Options menu (Alt + M) to the left of where it says Build and Run, and above the drop down menu that lets you select the version of Java (or other language) that your using. After you click Modify Options the first box you will see--titled Operating System--will have a line that says "Redirect input". Click on that to add the box for input redirection. Close Modify Options. Under Build and Run, the third box down is for command line input.

Intelij IDE的图片与编辑配置框打开箭头指向cmd行输入和输入重定向

这就是它的全部。