开发者

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开发者_StackOverflow "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


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 %*


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜