title: How to create a batch file to run a jar file that is in any location of the system
body: <p>I have a MyFile.jar file. I need a batch file that searches for the jar file and triggers it.</p>
  
  <p>I found the following solution. But for that batch file and jar file must be in the same folder. </p>
  
  <pre><code>java -jar %~dp0MyFile.jar %*
  </code></pre>
  
  <p>We don't know where the client will place jar file in their system. But they will put batch file in startup folder.</p>
  
  <p>Edit: I managed to write this batch file for now. </p>
  
  <pre><code>`ECHO
   ECHO Locating the Jar
  
   IF EXIST java -jar MyFile.jar  ELSE (GOTO 
  
   SearchJar)
  
  :SearchJar
  SET the_path=D: &amp; CD\
  DIR /S/B File.jar &gt; installer_location.txt
  SET /P the_path=&lt; installer_location.txt
  if defined the_path goto :FoundIt
  
  E: &amp; CD\
  DIR /S/B MyFile.jar &gt; installer_location.txt
  SET /P the_path=&lt; installer_location.txt
  if defined the_path goto :FoundIt
  
  C: &amp; CD\
  DIR /S/B MyFile.jar &gt; installer_location.txt
  SET /P the_path=&lt; installer_location.txt
  if defined the_path goto :FoundIt
  
  G: &amp; CD\
  DIR /S/B MyFile.jar &gt; installer_location.txt
  SET /P the_path=&lt; installer_location.txt
  if defined the_path goto :FoundIt
  
  H: &amp; CD\
  DIR /S/B MyFile.jar &gt; installer_location.txt
  SET /P the_path=&lt; installer_location.txt
  if defined the_path goto :FoundIt
  
  I: &amp; CD\
  DIR /S/B MyFile.jar &gt; installer_location.txt
  SET /P the_path=&lt; installer_location.txt
  if defined the_path goto :FoundIt
  ECHO Jar not found.
  
  :FoundIt
  ECHO Jar file found at %the_path%
  
  CALL java -jar %the_path%`
  </code></pre>
  
  <p>This is working now in my system. But I am not sure if there will be a simpler way to check all the drives at once. </p>