Search code examples
javanetbeanscommand-lineprogram-entry-pointargs

NetBeans IDE, set command line arguments and run as main project, however, nothing is showing


I'm new to Java and is trying to learn the command line arguments using NetBeans IDE. Below is the code I used to test command line arguments.

public class Echo {
    public static void main (String[] args) {
        for (String s: args) {
            System.out.println(s);
        }
    }
}

I went to Project --> Properties --> Run --> and type the arguments (i.e. a b c) next to "Arguments", I run the project from: run -- > run main project. However, no command line arguments were printed out? Why is this happening?

enter image description here

enter image description here


Solution

  • You have to use the big green arrow to run your project, or right-click on the project itself and select "Run.." from the menu.

    If you use Shift-F6 ("Run File") it won't supply the command line arguments. Those are for the project only.