title: Package a batch file within a jar file
body: <p>I would like to know if its possible to 'package' (as single jar) a batch file together with my java application. My application executes a batch file and hence hard-coded I've had to write the path of the batch file. My concern is that i would like that i can call the batch file without the need to alter the path for each and every machine i deploy my application.... Using Eclipse as an IDE.</p>
  
  <p>Here is my code which works fine, but as i said i would love to call the batch file for example as a normal java class import....</p>
  
  <pre><code>public class LogFileScanner 
  {
                  private final String dir_of_log = "&lt;My Directory&gt;";
                  private final String dir_of_batch = "&lt;My Directory&gt;\\Java_Tools";
                  private final int toGigaByte = (1024*1024)*1024;
                  private double size_in_GIGA;
                  private String cur;
          .
          .
          .
  
      try
      {
          Runtime.getRuntime().exec("cmd /c start DailyAuto2.bat", null, getBatchFile());
      }
          .
          .
          .
  
      private File getBatchFile()
      {
              File batchFile = new File(dir_of_batch);
              return batchFile;
      }
  }
  </code></pre>
  
  <p>Thanks very much for any input given.</p>
  
  <p>Solved my problem by using the following :</p>
  
  <pre><code>private File getBatchFile()
  {
      dir = LogFileScanner.class.getResource("DailyAuto2.bat").toString();
      dir = dir.replace("/", "\\\\");
      dir = dir.substring(7, dir.length()-16);
      File batchFile = new File(dir);
      return batchFile;
  }
  </code></pre>