Posts which you will also like.

Friday, August 3, 2012

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:

eclipse1

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


eclipse


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.


eclipse3

Thats it.

More on this at techcresendo.com

No comments:

Post a Comment

Your comment may wait for moderation....

DMCA.com Protected by Copyscape Online Plagiarism Tool