How to pass console arguments to application in eclipse?

前端 未结 8 1525
广开言路
广开言路 2020-11-27 16:03

I have the following line in a batch file.

java Client \"127.0.0.1\" 9876

It contains the name of my java class and two arguments. My applicatio

8条回答
  •  天涯浪人
    2020-11-27 16:11

    this work for me, in public static void main method.

    public static void main(String argv[]) throws Exception {
        int port_com = 2;
        boolean debugMode = true;
        int socket = 6789;
        HasarMain hasarMain = new HasarMain();
    
        // Check if a command line argument exists
        if(argv.length != 3){
            System.out.println("Missing, Port - socket - debugMode!");
            System.exit(0);
        }
    
        port_com = Integer.parseInt(argv[0]);
        socket = Integer.parseInt(argv[1]);
        debugMode = Boolean.parseBoolean(argv[2]);
    

    Run-> Run Configurations->Arguments->Enter your arguments separated by tab->

    ${string_prompt:argv:"2" "6789" "true"}

提交回复
热议问题