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.
Author by
Admin
Updated on August 21, 2022Comments
-
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 almost 12 yearsHey, 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 almost 12 yearsSo 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 almost 12 yearsDo you have some sort of quick on how to do so?
-
Anthony Accioly almost 12 yearsThis 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 almost 12 yearsI pasted that in to TextEdit and saved it as "filename" on desktop, how excatly do I do the chmod u+x thingy?
-
Anthony Accioly almost 12 yearsOpen a terminal, cd to your Desktop and type
chmod u+x filename
. -
Admin almost 12 yearsDid that now, still opens in TextEdit :/
-
Anthony Accioly almost 12 yearsI 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 almost 12 yearsAlright, 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 almost 12 yearsIt is not working, it just opens up Terminal but after that nothing.
-
Anthony Accioly almost 12 yearsIs it working when you run
java -Xmx256m -jar /Users/John/Desktop/RSBot/RSBot-4025.jar
directly on the terminal? -
Admin almost 12 yearsYes, 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 almost 12 yearsYou 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 almost 12 yearsAlright. 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 almost 12 yearsThis is what I got now: Johns-Mac-Pro:~ John$ /Users/John/Desktop/myshellscript.sh ; exit; Error: Unable to access jarfile RSBot*.jar
-
Admin almost 12 yearsYaaay! 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 almost 12 years@user1552321 - you appear to have two Xmx settings. Is that right ? Is one of them an Xms ?