Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to pass console arguments to application in eclipse?

Tags:

java

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 using the values of the arguments in the code but I'm curious.

like image 501
ThePetest Avatar asked Sep 27 '11 19:09

ThePetest


People also ask

How do you pass a file to a command line argument in Java?

public static void main(String[] args) { fileReader fr = new fileReader(); getList lists = new getList(); File CP_file = new File("C:/Users/XYZ/workspace/Customer_Product_info. txt"); int count = fr. fileSizeInLines(CP_file); System. out.

How do I get the command line in Eclipse?

A fully working command-line Terminal inside Eclipse. Just press Ctrl+Alt+T to open a local command prompt (Terminal).


2 Answers

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

like image 135
Jon Skeet Avatar answered Sep 24 '22 17:09

Jon Skeet


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

like image 27
Miserable Variable Avatar answered Sep 25 '22 17:09

Miserable Variable