How to run .jar through terminal with more RAM allocated on Mac

11,378

You need some sort of shell script. It would look similar to

#!/bin/sh
java -Xmx256m -jar /path/to/jarfile.jar

The -XMx setting determines the maximum amount of RAM the JVM will allocate to your Java program.

See here for how to make this double-clickable from the Mac Finder.

Share:
11,378
Admin
Author by

Admin

Updated on August 21, 2022

Comments

  • Admin
    Admin almost 2 years

    I want to run a .jar program on my Mac from a "bat" file or w/e dont know what it is on Mac.

    Why I wan't to do this is because I want to allocate more RAM to the .jar.

    Can anyone help out on how to do so? :)

    I just want to click on a file and it opens up the .jar file with more RAM allocated automatic.

  • Admin
    Admin almost 12 years
    Hey, yes I know that command. But I just want to create a file to click on so it writes that in automaticly, is it possible?
  • Brian Agnew
    Brian Agnew almost 12 years
    So create that shell script, make sure it's executable and you should be able to do that via the Mac Finder. See also my edit above
  • Admin
    Admin almost 12 years
    Do you have some sort of quick on how to do so?
  • Anthony Accioly
    Anthony Accioly almost 12 years
    This is a clickable file. Just open your text editor and paste the contents in. When you are done, save it (with no extension or .sh extension). Also give executable permission to your file with chmod u+x. After that you can double click on your shell script just like you do with .bat files.
  • Admin
    Admin almost 12 years
    I pasted that in to TextEdit and saved it as "filename" on desktop, how excatly do I do the chmod u+x thingy?
  • Anthony Accioly
    Anthony Accioly almost 12 years
    Open a terminal, cd to your Desktop and type chmod u+x filename.
  • Admin
    Admin almost 12 years
    Did that now, still opens in TextEdit :/
  • Anthony Accioly
    Anthony Accioly almost 12 years
    I don't have access to a OS X box right now, but I guess the problem is either the extension or the way TextEdit is saving your file. Try creating a new file with nano (from your terminal type nano myshellscript.sh), paste your contents and give it +x permission.
  • Admin
    Admin almost 12 years
    Alright, do I paste in what I wrote in TextEdit in the Nano window and then save it? How do I give it +x permission? This is command I'm using btw: #!/bin/sh java -Xmx256m -jar /Users/John/Desktop/RSBot/RSBot-4025.jar
  • Admin
    Admin almost 12 years
    It is not working, it just opens up Terminal but after that nothing.
  • Anthony Accioly
    Anthony Accioly almost 12 years
    Is it working when you run java -Xmx256m -jar /Users/John/Desktop/RSBot/RSBot-4025.jar directly on the terminal?
  • Admin
    Admin almost 12 years
    Yes, it's working when I first write java -Xmx256m -jar then drag the jar in. I can also make it work by writing java -Xmx256m -jar java -jar -Xmx1024m RSBot*.jar
  • Anthony Accioly
    Anthony Accioly almost 12 years
    You just need the exactly command that runs on your terminal inside the sh file. Come up with a command that works using full paths like the one above, once you can get it to run in the terminal just paste it inside your sh file and it will work.
  • Admin
    Admin almost 12 years
    Alright. So wheen i save it from TextEdit do i save it like "filename.sh" or without sh? Because ur first answer u said w/o .sh
  • Admin
    Admin almost 12 years
    This is what I got now: Johns-Mac-Pro:~ John$ /Users/John/Desktop/myshellscript.sh ; exit; Error: Unable to access jarfile RSBot*.jar
  • Admin
    Admin almost 12 years
    Yaaay! It's working now! This made it work: #!/bin/sh java -Xmx256m -jar -Xmx1024m /Users/John/Desktop/RSBot/RSBot-4025.jar Thank you so much Anthony, I have been trying to do this for days now!
  • Brian Agnew
    Brian Agnew almost 12 years
    @user1552321 - you appear to have two Xmx settings. Is that right ? Is one of them an Xms ?