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


当前回答

主程序->运行->编辑配置->在“配置”中有“程序参数”文本框。在文本框中添加空格分隔的参数。然后你可以在args数组中读取这些参数(public static void main(String[] args))

其他回答

自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行输入和输入重定向

这就是它的全部。

主程序->运行->编辑配置->在“配置”中有“程序参数”文本框。在文本框中添加空格分隔的参数。然后你可以在args数组中读取这些参数(public static void main(String[] args))

如果你正在使用intellij去运行>编辑配置菜单设置。将出现一个对话框。现在您可以向Program arguments输入字段添加参数。

正如@EastOcean所说,我们可以通过选择运行/调试配置选项来添加它。 在我的情况下,我必须为junit设置配置。因此,在单击Edit configurations选项时,会显示一个弹出窗口。然后按照以下步骤进行:

点击+图标 从列表中选择junit 然后我们可以在右边看到Configuration选项卡 选择测试类型,在我的情况下,它是一个类 下一步,浏览需要执行/运行的类的位置 接下来,选择虚拟机选项,单击展开箭头图标 为示例设置必要的参数(-Durl="http://test.com/home" -Dsourcename="API") -Dbrowsername =“铬”) 设置jre路径。

保存并运行。

谢谢你!

Windows、Linux和部分mac电脑:

ALT+SHIFT+F10,右,E, Enter, Tab,输入你的命令行参数,Enter。: -)

Mac的“OS X 10.5”键模式:

CTRL+ALT+R,右,E, Enter, Tab,输入你的命令行参数,Enter。