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.
Asked
Active
Viewed 629 times
-3
-
2And the question is? – Vincent De Baere Jul 02 '15 at 05:20
-
please give example of input and expected output – Sharon Ben Asher Jul 02 '15 at 05:22
-
possible duplicate of [Java - Read CSV with Scanner()](http://stackoverflow.com/questions/14274259/java-read-csv-with-scanner) – Ognyan Dimitrov Jul 02 '15 at 05:23
-
Input is a few parameters for a functionality. For example, while dealing with ports, portId is an input. Inputs are fine. I just need to know how do I make eclipse read those inputs that are given in the batch file. – vivek narayan Jul 02 '15 at 05:26
-
Decide either you run your program just using command line or set Run Configurations, command args in Eclipse. Your are mixing 2 things i.e. trying to do something wrong. – Rajesh Jul 02 '15 at 06:16
2 Answers
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,080
- 1
- 17
- 23
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
- 830
- 3
- 19
- 40