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

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

问题描述

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

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

  javac filename.java 
java filename -30

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



谢谢:)

解决方案

在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天全站免登陆