Netbeans如何在Java中设置命令行参数 [英] Netbeans how to set command line arguments in Java

查看:39
本文介绍了Netbeans如何在Java中设置命令行参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在 Windows 7 64 位上的 Netbeans 7.1 Java 项目中设置命令行参数.

I am trying to set command line arguments in a Netbeans 7.1 Java project on Windows 7 64 bit.

Netbeans 没有传递我给它的参数.

Netbeans is not passing the arguments I give it.

我转到 Project --> Properties --> Run --> 并在Arguments"旁边键入参数,但是参数不传递给程序.我如何通过它们?

I go to Project --> Properties --> Run --> and type the arguments next to "Arguments" however the arguments are not passed to the program. How do I pass them?

推荐答案

我猜你正在使用 Run |运行 File(或 shift-F6)而不是 Run |运行主项目.NetBeans 7.1 帮助文件(F1 是您的朋友!)Arguments 参数的状态:

I am guessing that you are running the file using Run | Run File (or shift-F6) rather than Run | Run Main Project. The NetBeans 7.1 help file (F1 is your friend!) states for the Arguments parameter:

添加参数以在应用程序执行期间传递给主类.请注意,参数不能传递给单个文件.

Add arguments to pass to the main class during application execution. Note that arguments cannot be passed to individual files.

我用一小段代码验证了这一点:

I verified this with a little snippet of code:

public class Junk
{
    public static void main(String[] args)
    {
        for (String s : args)
            System.out.println("arg -> " + s);
    }
}

我将 Run -> Arguments 设置为 x y z.当我自己运行文件时,我没有得到任何输出.当我运行项目时,输出是:

I set Run -> Arguments to x y z. When I ran the file by itself I got no output. When I ran the project the output was:

arg -> x
arg -> y
arg -> z

这篇关于Netbeans如何在Java中设置命令行参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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