开发者

How to pass console arguments to application in eclipse?

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 application requires these arguments to run properly.

Is there any way to pass these arguments when running the application in eclipse? It would make debugging a lot easier. Of course I could resolve the problem by 开发者_JS百科using the values of the arguments in the code but I'm curious.


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:

How to pass console arguments to application in eclipse?


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


  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

How to pass console arguments to application in eclipse?


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

How to pass console arguments to application in eclipse?

Hope it helps.


From "Run" go to debug/run configurations. Click the tab called "Arguments". You can give the program arguments there.


Run configurations > Arguments tab. Just put "127.0.0.1" 9876 in the program arguments.


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


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"}

How to pass console arguments to application in eclipse?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜