Niraj
Niraj

Reputation: 1

How to write a batch file which specifies what args need to be passedto run a Java application?

I am building a client for my application. I am building a tool for automating triaging and the client should only write a command like the following:

run-at testData 1234

where run-at would be my .bat file and "testData" and "1234" are arguments. So, basically it is a command which will print the testData for the buildNumber - 1234.

I have to call the main class which is CommandLineClient.java Right now, in my run-at.bat this is what I have:

@ECHO OFF
java -classpath lib/*;. com.vmware.autotriage.client.CommandLineClient [args]

How to specify arguments in a batch file which can call the function in my Main class.

Thanks in advance. Niraj

Upvotes: 0

Views: 1136

Answers (2)

Colin M.
Colin M.

Reputation: 455

For Windows batch files, using "%" and a number indicates a series of arguments passed to the batch file, so you would, for your example of two parameters to be accepted, do:

java -classpath lib/*;. com.vmware.autotriage.client.CommandLineClint %1 %2

This would take the first two parameters specified to in the batch file call and provide them to the main() method of your Java program.

For reference, it is "$" instead of "%" on non-Windows platforms. You might want to tag this with more than "android" to get more answers.

Upvotes: 0

beny23
beny23

Reputation: 35008

In order to pass all arguments passed into the .bat file to your Java client, use the following:

@ECHO OFF
java -classpath lib/*;. com.vmware.autotriage.client.CommandLineClient %*

Upvotes: 1

Related Questions