17

In Java, for a normal main method :

public static void main(String[] args){
    // code here
}

String[] args is used to take some parameters from command line. I can run this file from command prompt by :

javac filename.java
java filename -30

But, it takes more steps, and I must cd to this folder. (to long for each time). So, Does anyway to run this file with some arguments for main in Eclipse.

Thanks :)

hqt
  • 29,632
  • 51
  • 171
  • 250
  • 2
    Did you even slightly research this? First hit for `eclipse java arguments main` gives you the answer on Google. -1. – Duncan Jones Aug 31 '12 at 20:41

4 Answers4

31

In Eclipse you can set up a Run Configuration for the Java Application. Click on the green "play" button in the Launch toolbar (next to the bug icon which starts debugging).

Within that configuration, you can set the working directory and command line arguments - and even prompt the user for command line arguments when it's run, using arguments like ${string_prompt:Foo}.

Jon Skeet
  • 1,421,763
  • 867
  • 9,128
  • 9,194
18

Right click the class. Then go to Run as > Run configurations. Select the program on the left side. Then on the arguments tab you will see Program Arguments. Enter your program arguments in this textarea, if you would like to pass multiple arguments separate the arguments by spaces.

enter image description here

This site provides a good step by step tutorial with images: http://www.javaprogrammingforums.com/java-jdk-ide-tutorials/362-how-send-command-line-arguments-eclipse.html

Kevin Bowersox
  • 93,289
  • 19
  • 159
  • 189
3

Right click on program with main method---> Select Runtime Configuration--> There you will see a box for argument on right side.

kosa
  • 65,990
  • 13
  • 130
  • 167
1

It was weird that I had to pass each argument in a new line but after reading a bit it made sense to me(overlooked the fact that they(Arguments) are instances of String). Multiple Arguments for a PSVM

Abhijeet
  • 8,561
  • 5
  • 70
  • 76