Netbeans Input Parameters

I am new to java development in Netbeans and I am having a problem entering input parameters in Netbeans. If I create a project and start the jar using cmd, everything works fine, but I donโ€™t know how to provide parameters in the IDE.

Here is an example for testing:

public class NetbeansRunParams {

    public static void main(String[] args) {

        if (args.length != 3) {
            System.out.println("Missing input arguments!");
            System.out.println("Run example: java -jar test.jar agrument1 argument2 argument3");
            System.exit(0);
        }        

        System.out.println(String.format("First argument has value: %s", args[0]));
        System.out.println(String.format("Second argument has value: %s", args[1]));
        System.out.println(String.format("Third argument has value: %s", args[2]));

    }
}

So, every time I run this code using Netbeans, I get the following output in the console:

run:
Missing input arguments!
Run example: java -jar test.jar agrument1 argument2 argument3
BUILD SUCCESSFUL (total time: 0 seconds)
+4
source share
1 answer

Hey hello and welcome! You can set the input parameter if you left-click on the project in netbeans and select propprties. Then go to run and add the arguments here. Here is a screenshot with some arguments:

enter image description here

+4
source

Source: https://habr.com/ru/post/1585068/


All Articles