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

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

问题描述

在开发(和调试)期间,直接从 Eclipse 内部运行 Java 类的 public static void main(String[] argv) 方法非常有用(使用 Run As 上下文菜单).

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).

是否有类似的快速方法来为运行指定命令行参数?我现在要做的是转到运行对话框",单击各种设置到选项卡,在那里我可以指定 VM 和程序参数并在那里输入它们.步骤太多,而且我不想将更永久的运行时配置设置与一次性调用参数混合在一起.我想要的是在某处选中一个框(或者有一个单独的菜单项使用命令行作为 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.

选择 Run As... 时,进入运行配置.

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

在 Java 运行配置的 Arguments 选项卡上,将变量 ${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天全站免登陆