Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Running jar with dropped file on bat

I want to drag and drop a file on a .bat file. After I dropped it I want to run a jar file with the dropped file path as input. How can I accomplish to run the jar file with a relative path? The dir my .bat file is run is my user dir and not the dir where it is located.

goal: cmd /c java -jar myjar.jar -f %1
current: cmd /c java -jar c:\somewhere\myjar.jar -f %1

The point is, that the program(jar +bat) is part of a small automated deploy process and for every user there might be a different path to run the jar.

like image 571
lrxw Avatar asked Oct 28 '25 04:10

lrxw


1 Answers

Perhaps this works, it changed the current directory to the path of the batch-file

pushd "%~dp0"
cmd /c java -jar myjar.jar -f "%~1"
like image 182
jeb Avatar answered Oct 30 '25 23:10

jeb



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!