How to run a Java JAR file with a batch file from the different folder.
If you want to start a JAR file with a batch it works, if you run the batch file from the same folder like that. However, if you run the batch file from a different folder, you get an error:
Error: Unable to access jarfile
The problem is, that the JAR file is looked up in the current folder. In order to start the batch file from any folder, we can use the „
%~dp0“ variable. A good explanation can be found here.
Basically, is fills out the drive name and folder information for us.
So the call would look like that:
java -jar %~dp0\Application-1.0-SNAPSHOT-shaded.jar