Here’s a quick demo on launching a Minecraft server in Windows using a .bat file.
- Right click in your folder and go to New > Text Document.
- Name it start_server.bat
- Hit Yes when windows asks if you’re sure about changing the extension.
- Now right click the file and hit Edit.
- Paste in the following text, and change it to match your situation. I’ll explain each part to better help you make the necessary changes.
12"C:\Program Files (x86)\Java\jre7\bin\java.exe" -Xmx1024M -Xms512M -jar forge_server.jar noguiPAUSE
- The first bit is a call to your system’s Java installation. It needs to be in quotes because of the space in Program Files (x86). To find yours, look in either your Program Files or Program Files (x86) to find Java.
- Next are two options that tell Java how much RAM it can use. -Xmx is the maximum, and -Xms is how much it’ll start with. You can specify in Megabytes or Gigabytes.
- Here’s the -jar option along with the name of your .jar file. Here you can just put the name of the .jar file you want to launch as long as it’s in the same directory as your .bat script.
- nogui tells the Minecraft server not to start the GUI part of the application. Opening the server through a script means it’ll be running in a console window. There’s no need for a GUI when you have a much better looking terminal to view.
- PAUSE simply makes the window wait for you to “hit any key to continue…” after you “stop” the server. I like doing this out of habit in certain situations, you can take it or leave it.
By simply changing the .jar file called by this script, you can use it to launch either a vanilla server or a modified server like Forge. I’m not a Windows script pro by any means (I’m usually using Linux), but if you have any questions please feel free to ask in the comments below!
There are 54 comments on this post
i get this error help
Could not find or load main class net.minecraft.client.Main
Alright so when i get this running cmd opens, shows the input i gave and initiates the pause we added right away, doesnt tell me whats wrong whatsoever i dont understand.
Is this the same process if you wanted to run the server using windows Powershell (windows 10)? I would assume if so, that all you do is direct the batch file to run powershell instead of your java installation?
AFAIK Powershell would be replacing the CMD, it's just a shell to run commands. I believe pointing to java is required regardless of the shell used to start it.
When i doubletap start_server.bat it opens as start_server.bat.txt, plz help.
You need to change your view settings for folders/files in Windows.
Allow showing of File name extensions. This will show the file is actually named start_server.bat.txt because it was created as a text document.
Remove .txt and it will ask if you're sure you want to change the file type. Click yes.
My run.cmd on Windows 7
@ECHO OFF
--variables
set folder_world=_world_
set folder_backup=_backup_
set author=Duke49
set jar=server.jar
set minram=4096M
set maxram=4096M
set end_pause=0
--code
cls
for /f "delims=[] tokens=2" %%a in ('ping -4 -n 1 %ComputerName% ^| findstr [') do set LocalIP=%%a
for /f "tokens=2 delims=: " %%A in ('nslookup myip.opendns.com. resolver1.opendns.com 2^>NUL^|find "Address:"') Do set PublicIP=%%A
color CF
echo.
echo.
echo.
echo *- - - - - - - - - - - - -*
echo * *
echo * SERVEUR MINECRAFT *
echo BY %author%
echo * *
echo *- - - - - - - - - - - - -*
echo *
echo * Local IP: %LocalIP%
echo * Public IP: %PublicIP%
echo *
echo *- - - - - - - - - - - - -*
echo.
echo.
echo 1 - Sauvegarder la carte
echo 2 - Ne pas sauvegarder la carte
echo 3 - Quitter
echo.
CHOICE /C 123 /M "Faire un choix : "
IF ERRORLEVEL 3 GOTO END_SERVER
IF ERRORLEVEL 2 GOTO START_SERVER
IF ERRORLEVEL 1 GOTO SAVE_YES
:SAVE_YES
echo.
echo.
echo * * * * * * * * * * * * * * * * *
echo WOLRD BACKUP
echo * * * * * * * * * * * * * * * * *
echo.
xcopy /e /y %folder_world% %folder_backup%
goto START_SERVER
:START_SERVER
echo.
echo.
echo * * * * * * * * * * * * * * * * *
echo STARTING SERVER
echo * * * * * * * * * * * * * * * * *
echo.
java.exe -XX:+UseConcMarkSweepGC -XX:+UseParNewGC -XX:+CMSIncrementalPacing -XX:ParallelGCThreads=2 -XX:+AggressiveOpts -Xms%minram% -Xmx%maxram% -jar %jar% nogui
goto END_SERVER
:END_SERVER
echo.
echo.
echo * * * * * * * * * * * * * * * * *
echo CLOSING SERVER
echo * * * * * * * * * * * * * * * * *
echo.
echo.
if %end_pause% ==1 pause >nul
exit
Use the following to launch the version of forge present, rather than having to dit the forge-filename or your sript with each new version of forge you run.
FOR /f "tokens=*" %%G IN ('dir /b forge*.jar') DO java -Xmx6G -Xms6G -jar %%G -Dfml.queryResult=confirm nogui
whenever i start the batch file, my windows says '\program' is not recognized as an internal or external command, operable program or batch file. HELP
Sounds like you don't have the quotes around your command. The space in Program Files is why you need quotes so it doesn't break up the command.
Hey, I've got a bit of an issue. Whenever I try and change the values to something higher than they are in your example (Xmx512 and Xms1024), the console always has a problem and cant launch the server, when the entire reason I made the batch file was to allocate more ram for the server to use!
I tried increasing the values to Xmx1024 Xms2048 and got:
Error occurred during initialization of VM
Could not reserve enough space for 2097152kb object heap
And when I increase them to Xmx3072 Xms2048, it says:
Error occurred during initialization of VM
Could not reserve enough space for 3145728kb object heap
And if I try 4096 and 2048, it says:
Invalid maximum heap size: -Xmx4096M
The specified size exceeds the maximum representable size.
Error: Could not create the Java Virtual Machine.
Error: A fatal exception has occured. Program will exit.
My computer has 8.00 GB of ram, so options like Xmx1024 Xms2048 to someone who doesn't understand Java at all like me should seemingly work fine, I don't understand why it won't let me increase values. Any input would be appreciated because I don't understand it, and I can't find anyone else asking this specific question.
Not sure if you've figured it out, but the Xmx is the maximum ram it can use, while Xms is what it starts out with. Make Xms the smaller of the two figures and Xmx the larger, and you should be good.
Run the .bat as Computer ADMIN.
ok total noob here i downloade the 1.10 from minecrat.net i have a 64bit wind 10 java update 3 days ago and i cant get a batch file to work please help
i keep doing the steps in the correct order. i right click in the folder, i click new -> text document, i name it start_server.bat, then i hit enter but it doesnt ask me if im sure if i want to change the extension. so its not actually making a .bat file its staying at a .txt. can you please help me. ive been trying all day to find a solution
Go to: Control Panel > All Control Panel Items > File Explorer Options > View. Then, uncheck the box "Hide extensions for known file types"
the jar files name has to match the jar file in your folder and they have to be in the same folder it won't work on your desktop put the entire server into a file then run start_server.bat although the start_server.bat can be named anything
I have done all of this, but I would actually like to use the server gui. How can I do this?
Not sure if you've been answered yet, but just remove the 'nogui' from the line and it will open the gui as it starts the server.
OMG THANKS! It is finnaly working!
If I switch between Java 7 and Java 8. Don't I need the javaw.exe because that is what most java programs use?
If you switch between Java 7 and Java 8, I would make two different .bat files. One for each java you want to call. However, you still want to call java.exe. The javaw.exe is used for GUI-based programs, which is why most programs use it. The server is strictly in the terminal and is why you don't need the 'w' version.
This guy has a really good minecraft server script
https://youtu.be/WL2RE4s2O6s
im trying to make a vanilla server and i noticed in the code line it say forge server. can i just change that to minecraft server and il be fine or is there another way i have to do it?
Yes I just used forge_server.jar as an example. You can use any server.jar, including the vanilla one. Just make sure to change the line of code to match the name of the .jar you are calling.
Whenever I start the batch file, it says "ERROR: unable to access jarfile forge_server.jar
Is your .jar file actually named forge_server.jar? This line in your .bat file needs to call the correct file. My example was forge_server.jar but yours could be named anything.
wait but where do we find this .jar file that you're talking about. the one we need to name in the code
I know it's been a while, but I'm trying to set up a local server and can't seem to get the batch file to increase my RAM. Has the process changed in the jre1.8.0_51 version? Also is start_server.bat still appropriate for the forge universal.jar?
The process is still the same for newer versions of java. Yes you can still use start_server.bat to run a forge server.
When I use the batch file, it says "The system cannot find the path specified."
I typed in where my java file was, in quotes, of course.
It's possible you're missing a space or maybe you don't have quotes around the location? You need the quotes to automatically escape any special characters or spaces. Paste your line 1 in a comment here and I'll look at it to see if I can figure out the problem.
when i change the name to "start_server.bat" it doesn't ask me anything about a change and it stays as a text document
My first thought is that you have Windows hiding the file extension types. If that's the case then your file is actually being named "start_server.bat.txt" and would of course stay as a text file. Search google for "Windows show file extensions" for instructions on how to make sure you see them. Let me know if this doesn't work and I'll try to help more!
Make sure you click "save as", choose a name, and last but not least make sure to change the "save as type" from "text document" to "all files" Sorry if this is messy I was typing off memory. Good luck!
No console window:
@echo off
start /b javaw -Xmn1G -Xms1G -Xmx2G -XX:NewSize=512M -XX:SurvivorRatio=2 -XX:+DisableExplicitGC -XX:ParallelGCThreads=4 -d64 -XX:+UseConcMarkSweepGC -XX:+CMSIncrementalPacing -XX:+AggressiveOpts -jar forge-1.7.10-10.13.2.1291-universal.jar
I don't know where the exception comes from, it's annoying but doesn't prevent the server from running; I will live with it. :)
The exception is likely due to all the extra options you're using. I'm not familiar with them so one of them could be the culprit. Honestly though I don't understand going through the trouble of getting rid of a console window. Once the server is started it's no longer a console window, it becomes the server. It gives you info on what's going on, who's doing what, etc.
Honestly I beg to differ about the GUI thing, I find the server GUI more useful and more pleasant to look at than the CMD window.
there is a slight problem though. I changed "java.exe" to "javaw.exe" so I could use the GUI and close the CMD window once the server had been started. However the server spits out this message.
[12:46:08 ERROR]: Exception handling console input
java.io.IOException: Not enough storage is available to process this command
at java.io.FileInputStream.readBytes(Native Method) ~[?:1.7.0_67]
at java.io.FileInputStream.read(Unknown Source) ~[?:1.7.0_67]
at java.io.BufferedInputStream.read1(Unknown Source) ~[?:1.7.0_67]
at java.io.BufferedInputStream.read(Unknown Source) ~[?:1.7.0_67]
at sun.nio.cs.StreamDecoder.readBytes(Unknown Source) ~[?:1.7.0_67]
at sun.nio.cs.StreamDecoder.implRead(Unknown Source) ~[?:1.7.0_67]
at sun.nio.cs.StreamDecoder.read(Unknown Source) ~[?:1.7.0_67]
at java.io.InputStreamReader.read(Unknown Source) ~[?:1.7.0_67]
at java.io.BufferedReader.fill(Unknown Source) ~[?:1.7.0_67]
at java.io.BufferedReader.readLine(Unknown Source) ~[?:1.7.0_67]
at java.io.BufferedReader.readLine(Unknown Source) ~[?:1.7.0_67]
at pr.run(SourceFile:81) [PixelIsStranded.jar:?]
(PixelIsStranded.jar is the vanilla server file)
It appears that everything is working fine, but I know that is not normal. I have run servers for the personal use of friends and myself for several years, and this message hasn't popped up before. Can you help me figure out how to fix this?
The console being better looking may just be my opinion but the fact is it takes up less system memory than the GUI.
Best way to find info on your issue is to search for the exception you're getting. Generally at the top of the error output. Here we have "Not enough storage is available [...]". Sounds like your hard drive might be getting full. If not, it's possible this is just a bug.
If it's not a full hard drive and the problem persists, try changing your setup. Maybe turn off the GUI or try a bukkit server.
Now I'm a complete newbie at making batch files, but what I've been using up until now is :
@echo off
"C:\Program Files\Java\jdk1.8.0_25\bin\javaw.exe" -Xmx1024m -Xms1024m -d64 -jar "minecraft_server.jar"
Problem is, the cmd window will stay up when it launches the server. What do I have to add to have it close automatically?
Most of the time a command will run and then the window can be closed. However, your server needs to keep running for people to connect. The window must stay open until the server is shut down. Think of the cmd window as your server. Typing 'stop' will save and quit, causing the cmd window to close automatically.
Also just an FYI, the @echo off isn't really needed in this case. More of a personal preference thing. All it does is stop the cmd window from printing your command at the top of the window. It'll scroll by and be gone so fast it doesn't matter.
yeah how?
do you make a jar file
Hey Andrey. The jar file is downloaded from the official minecraft website minecraft.net/download. Read the bottom paragraph and download the jar file from there.
im werd
I'm werd too. I've been looking for another werd for ages and now you've found me. Let's be werd together.
I am not sure about what to write in the batch file...
Step 5 shows what to write. If you are having trouble understanding the instructions above let me know specifically what is the problem.
it doesn't work for me. I'm stuck with the batch file. It keep says 'unable to access jarfile forge_server.jar
Make sure that either your .jar file is named forge_server.jar or change the script to match the name of your .jar file.
Also, the .jar file must be in the same folder as your .bat script. If you need the script to be somewhere else like on your desktop just make a shortcut to it.
how do you make a jar file?
Hi Becky, Brandon has created a very good basic process for creating a basic .bat (batch) file for starting a Minecraft server. Go to the top of his article and read from top to bottom paying attention to the details. Remember a "bat file" is nothing more than an simple text file who's file extension has been renamed from ".txt" to ".bat". Here's the link to the top of the article: https://www.brandonrubin.me/2013/10/07/minecraft-server-batch-file/