-3

I am developing an application in which users give an input in the batch file and that batch file input be given as an input to eclipse and oy will run a Java program(logic) and give the output either through a batch file or an excel.

2 Answers2

0

In Eclipse you can set arguments using Run > Run Configurations > Arguments

Running the jar file directly works just as simple: java -jar someFile.jar port ip whatever else

Those arguments will be passed to the main() method as a String[], so if you want numbers you will have to convert them.

public static void main(String[] args) {

        System.out.println(args[0]); // port
        System.out.println(args[1]); // ip
        System.out.println(args[2]); // whatever
        System.out.println(args[3]); // else
    }
dly
  • 1,042
  • 1
  • 16
  • 21
0

In the batch file you'll have something like this:

echo off
java -jar MyJavaJar.jar %1 %2 %*

Where %1 is the first parameter, %2 the second and %* anything else...

In your java class:

public static void main(String[] args) {
    //Check if args were supplied, e.g. args.length
    //else out put usage information
}

Hope this helps

TungstenX
  • 764
  • 3
  • 17
  • 37