Netbeans how to set command line arguments in Java

前端 未结 10 1312
陌清茗
陌清茗 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 16:52

    1. Create the Java code that can receive an argument as a command line argument.

      class TestCode{
          public static void main(String args[]){
              System.out.println("first argument is: "+args[0]);
          }
      }
      
    2. Run the program without arguments (press F6).

    3. In the Output window, at the bottom, click the double yellow arrow (or the yellow button) to open a Run dialog.

    4. If the argument you need to pass is testArgument, then here in this window pass the argument as application.args=testArgument.

    This will give the output as follows in the same Output window:

    first argument is: testArgument
    

    For Maven, the instructions are similar, but change the exec.args property instead:

    exec.args=-classpath %classpath package.ClassName PARAM1 PARAM2 PARAM3
    

    Note: Use single quotes for string parameters that contain spaces.

提交回复
热议问题