How to pass console arguments to application in eclipse?

前端 未结 8 1478
广开言路
广开言路 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:07

    Instead of just hitting the "Run" icon, select the dropdown box next to it, and choose "Run Configurations". Find your application (or create a Run Configuration for it) and put the command line arguments in the "Arguments" tab. See the docs for more information. It should look like this:

    enter image description here

    0 讨论(0)
  • 2020-11-27 16:10

    Run-> Run Configurations->Arguments->Enter your arguments separated by space->Apply->Run Ensure that the right project name and it's main method are selected under "the Main" tab under run configurations

    0 讨论(0)
  • 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"}

    0 讨论(0)
  • 2020-11-27 16:12

    See the run configurations. You can specify arguments. You can even prompt the user for arguments, along with defaults:

    ${string_prompt:host:127.0.0.1} ${string_prompt:port:9876}
    

    The first prompt is host, with default value 127.0.0.1 filled in. Second pop-up has the prmpt port, with 9876 filled in

    0 讨论(0)
  • 2020-11-27 16:16

    Want to add something like, how to add multiple parameters.

    1. Right-click on your project.
    2. Debug > Debug Configurations
    3. Go to Arguments tab.
    4. Enter in your Program Arguments, each separated by a new line. (e.g 3 arguments in attached image)
    5. Click Apply or Debug

    enter image description here

    Hope it helps.

    0 讨论(0)
  • 2020-11-27 16:19
    1. Right-click on your project.
    2. Go to Debug As > Debug Configurations or Run As > Run Configurations.
    3. Click the tab that says Arguments.
    4. Enter in your Program Arguments
    5. Click Apply or Debug

    enter image description here

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