0

I have a folder that has the batch file, along with a jar file and JRE. Batch file is supposed to run the jar by invoking the JRE. I know it would be something like:

   <jre-path>/bin/java.exe -jar <jar-path>Executable.jar

In batch file, how I would retrieve the absolute path of the folder which has all these jar and jre? There is an answer on SO for the question : what is the current directory in batch file that suggests to use %~dp0, but how would I use this in correct way for the command I mentioned above?

Community
  • 1
  • 1
user123
  • 15
  • 6

1 Answers1

1

First you decide relative path between the jar and the running script. The script will detect its location using the answer you already mentioned. (%~dp0 gives the directory)

mydir=%~dp0 
jardir=%mydir%/ 
..
java.exe -jar %jardir%/exectuble.jar

Another approach will be use product like launch4jenter link description here. You can access the install location from variable, provide user a nice looking launch icon, include jre with your packaging and more.

Jayan
  • 18,003
  • 15
  • 89
  • 143
  • jar file is in the same folder, i.e. no subdirectory. So I think I can use `java.exe -jar %mydir%/exectuble.jar`, Right? Also, is it not needed to specify the location of `java.exe` (keepng in mind that there may be a case where JRE is not installed on the machine where batch file is executing) ? – user123 May 16 '14 at 06:15
  • If there is no java.exe on the machine, you cannot run java.exe. Please consider the other option of packaging your product. – Jayan May 16 '14 at 06:20
  • I just asked for confirmation, let me just test the snippet to mark this question resolved. – user123 May 16 '14 at 06:21
  • I edited my answer to suite your case. If you just want some java, you can always use java.exe without absolute path. Normally java installation creates a dummy java.exe in system/win32 which will redirect to correct path. – Jayan May 16 '14 at 06:34