Eclipse:我们如何在运行时为 main 取参数 [英] Eclipse : how we take arguments for main when run

查看:39
本文介绍了Eclipse:我们如何在运行时为 main 取参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 Java 中,对于普通的 main 方法:

public static void main(String[] args){//代码在这里}

String[] args 用于从命令行获取一些参数.我可以通过以下方式从命令提示符运行此文件:

javac 文件名.javajava文件名-30

但是,这需要更多的步骤,我必须 cd 到这个文件夹.(每次都渴望).所以,无论如何都要在 Eclipse 中使用 main 的一些参数运行这个文件.

谢谢:)

解决方案

在 Eclipse 中,您可以设置一个 Java 应用程序的运行配置.单击启动工具栏中的绿色播放"按钮(在开始调试的错误图标旁边).

在该配置中,您可以设置工作目录和命令行参数 - 甚至在运行时提示用户输入命令行参数,使用诸如 ${string_prompt:Foo} 之类的参数.

In Java, for a normal main method :

public static void main(String[] args){
    // code here
}

String[] args is used to take some parameters from command line. I can run this file from command prompt by :

javac filename.java
java filename -30

But, it takes more steps, and I must cd to this folder. (to long for each time). So, Does anyway to run this file with some arguments for main in Eclipse.

Thanks :)

解决方案

In Eclipse you can set up a Run Configuration for the Java Application. Click on the green "play" button in the Launch toolbar (next to the bug icon which starts debugging).

Within that configuration, you can set the working directory and command line arguments - and even prompt the user for command line arguments when it's run, using arguments like ${string_prompt:Foo}.

这篇关于Eclipse:我们如何在运行时为 main 取参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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