Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

passing parameter to a jar file which is called in a bat file?

I have created a jar which needs to be called in a bat file. I need to pass all the command line arguments recieved by bat file to the jar. Can anyone please help me out. I know this is a stupid question, but i dont have any idea about jar and bat. On net i am unable to find the combination of both. Also note that i dont know how to retieve the command line arguments in the bat file.

like image 636
amod Avatar asked Dec 22 '22 08:12

amod


2 Answers

The parameters that you pass to your batch file can be accessed via

%1 %2 %3 ...

So if you call your batch like

C:>application.bat param1 param2 param3

then your java call inside the batch file should look like:

@echo off
java -cp app.jar com.example.Main %1 %2 %3
like image 132
Andreas Dolk Avatar answered Jan 24 '23 09:01

Andreas Dolk


Inside you bat file you will have java command
just use java -jar helloworld.jar firstParam secondParam and
I believe you can also use because that how we pass params to Maven and ANT etc

mybatchFile.bat -DfirstParam -DsecondParam
like image 35
Shahzeb Avatar answered Jan 24 '23 09:01

Shahzeb