Netbeans how to set command line arguments in Java

前端 未结 10 1278
陌清茗
陌清茗 2020-11-27 16:36

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

Netbeans is not passing the arguments I give it.

I go to

相关标签:
10条回答
  • 2020-11-27 17:06

    In NetBeans IDE 8.0 you can use a community contributed plugin https://github.com/tusharvjoshi/nbrunwithargs which will allow you to pass arguments while Run Project or Run Single File command.

    For passing arguments to Run Project command either you have to set the arguments in the Project properties Run panel, or use the new command available after installing the plugin which says Run with Arguments

    For passing command line arguments to a Java file having main method, just right click on the method and choose Run with Arguments command, of this plugin

    UPDATE (24 mar 2014) This plugin is now available in NetBeans Plugin Portal that means it can be installed from Plugins dialog box from the available plugins shown from community contributed plugins, in NetBeans IDE 8.0

    Run with Arguments plugin as shown in Plugin dialog box

    0 讨论(0)
  • 2020-11-27 17:07

    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);
        }
    }
    

    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
    
    0 讨论(0)
  • 2020-11-27 17:12

    If it's a Maven project then Netbeans is running your application using the exec-maven-plugin so you'll need to append your options onto the existing exec.args property found in the Run Maven dialog. This dialog can be accessed from the the Output window by pressing the yellow double arrow icon.

    enter image description here

    0 讨论(0)
  • 2020-11-27 17:14

    For passing arguments to Run Project command either you have to set the arguments in the Project properties Run panel

    0 讨论(0)
提交回复
热议问题