Is It Possible To Create a .jar File That Runs An Existing .bat File?

99 views Asked by At

I have a .bat file that I need to run from a .jar executable. I have looked around and can find no obvious way of doing so... Is there anyway this can be done? Help! Here is my existing .bat code if it helps:

@ECHO OFF

:: When setting the memory below make sure to include the amount of ram   
::      letter. M = MB, G = GB. Don't use 1GB for example, it's 1G ::

:: This is 64-bit memory ::
set memsixtyfour=2G

:: This is 32-bit memory - maximum 1.2G ish::
set memthirtytwo=1G

:: Don't edit past this point ::

if $SYSTEM_os_arch==x86 (
  echo OS is 32
  set mem=%memthirtytwo%
) else (
  echo OS is 64
  set mem=%memsixtyfour%
)
java -Xmx%mem% -XX:MaxPermSize=256M -jar forge-1.7.10-10.13.2.1277-universal.jar nogui
PAUSE
2

There are 2 answers

0
Pâris Douady On

I think what you are looking for is the Runtime class that can make System calls.

This is the code i would use :

Runtime.getRuntime().exec("cmd /c start your/path/yourbat.bat");
5
NilZzz On

Try adding this to your java code.

Runtime.getRuntime().exec("cmd /C start filename.bat");