使用Eclipse中的参数调用Java main方法 [英] Invoking Java main method with parameters from Eclipse

查看:326
本文介绍了使用Eclipse中的参数调用Java main方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在开发(和调试)期间,直接从Eclipse内部运行一个Java类'public static void main(String [] argv)方法非常有用(使用运行方式) 。

During development (and for debugging) it is very useful to run a Java class' public static void main(String[] argv) method directly from inside Eclipse (using the Run As context menu).

有一个类似的快速方式来指定运行的命令行参数?
我现在做的是转到运行对话框,点击各种设置到选项卡,我可以指定虚拟机和程序参数,并在那里输入。
太多的步骤,加上我不想将更加永久的运行时配置设置与一次性调用参数进行混合。
我想要的是在某个地方检查一个框(或者有一个单独的菜单项使用命令行运行Java应用程序),然后每次都提示输入命令行(具有很好的历史记录)。

Is there a similarily quick way to specify command line parameters for the run? What I do now is go to the "Run Dialog", click through the various settings to the tab where I can specify VM and program arguments and enter them there. Too many steps, plus I do not want to mix the more permanent runtime configuration settings with the one-off invokation parameters. What I want instead is to check a box somewhere (or have a separate menu item "Run as Java application with command line") and then be prompted for the commandline every time (with a nice history).

推荐答案

这个答案基于Eclipse 3.4,但应该在较旧版本的Eclipse中工作。

This answer is based on Eclipse 3.4, but should work in older versions of Eclipse.

选择运行方式...,进入运行配置。

When selecting Run As..., go into the run configurations.

在Java运行配置的参数选项卡上,配置变量$ {string_prompt}出现(您可以单击变量获取它,或复制直接设置它)。

On the Arguments tab of your Java run configuration, configure the variable ${string_prompt} to appear (you can click variables to get it, or copy that to set it directly).

每次使用该运行配置(命名它好,所以你有它稍后),系统将提示您输入命令行参数。

Every time you use that run configuration (name it well so you have it for later), you will be prompted for the command line arguments.

这篇关于使用Eclipse中的参数调用Java main方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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