Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

Passing Command Line Argument in Eclipse


Passing Command line arguments in Eclipse is very easy.We will see step by step procedure to Pass Command line arguments to a Java Program using eclipse.

package com.techy.rajeev;

class BadFoodException extends Exception {

}
class Myexception{
public static void checkfood(String food)throws BadFoodException{
if(food.equals("Veg")){
System.out.println("Good food :)");
}else{
throw new BadFoodException();
}
}
public static void main(String args[]){
for(String s: args){
try {
checkfood(s);
} catch (BadFoodException e) {
e.printStackTrace();
}
}
System.out.println("survived");
}
}


This is the java program for which we want to pass command line arguments.

Write this program in eclipse IDE and save it.

Now click on the small dropdown icon beside run icon as shown in image:



A drop down menu will appear.Now click on Run Configurations.





Now a new window will appear.This window provide us the settings for the run time configurations of a program.


In this window click on the arguments tab and supply the arguments needed by your program separated via space as delimiter.




Thats it.

More on this at techcresendo.com


This post first appeared on TechSoftEng, please read the originial post: here

Share the post

Passing Command Line Argument in Eclipse

×

Subscribe to Techsofteng

Get updates delivered right to your inbox!

Thank you for your subscription

×