Reputation: 709
I am trying to use this GUI mod for a Minecraft Server. I wrote a batch file so the server can start with more RAM. When I run just the .jar file, no command window opens and it runs just fine (of course with about 256mb ram) I was reading online that javaw starts a jar file without a command-line-console. But when I use javaw, the command console opens, but when I close it the program remains open. this is my batch file:
@echo off
"%ProgramFiles(x86)%\Java\jre6\bin\javaw.exe" -jar -Xms1024m -Xmx1024m crafty.jar
@echo on
I don't understand java as well as most, so please try to be as clear as possible. Thanks
Upvotes: 61
Views: 101512
Reputation: 41
I have a solution for my case: I wanted to start a server.jar without CMD or PowerShell window, only with the .jar window.
start.ps1
(Windows PowerShell Script) on your server directory, in this file should contains only the power shell command:Start-Process -FilePath java -WindowStyle Hidden -ArgumentList "-Xms2G -Xmx4G -jar server.jar"
Note if your have a specific directory to your java version, you can change the file path attribute, for example:
-FilePath "C:\YourSpecificDirectory\java\bin\java.exe"
instead of-FilePath java
.
In my case I have only one default version of Java in my PC and it's configured with JAVA_HOME environment variable, so I don't need to pass the complete file path like the example above.
To facilitate my use (I would like to start it from my Windows search bar, for example)
Create a Windows Shortcut with your prefered name in this Directory:
C:\Users\YOUR_USER\AppData\Roaming\Microsoft\Windows\StartMenu\Programs
Note to override the "YOUR_USER" to your current windows user name.
Shortcut file name example: MinecraftServer
The Target
field in the shortcut properties I put
powershell.exe -ExecutionPolicy Bypass -File start.ps1
The result target will be like this automatically
C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -ExecutionPolicy Bypass -File start.ps1
The Start in
field in the shortcut properties I put
C:\YourServerDirectory
Done! When you try to search for "Minecraft Server" on the search bar the system will recommend you this Shortcut. Once executed it will start your server only with the Minecraft Server window.
With this you can also create customized triggers with Windows Task Scheduler for running the script start.ps1. For example, whenever you log in your Windows User or when you start your PC.
Executing PowerShell command without Window
Running Java command with PowerShell
About PowerShell Execution Policy
Upvotes: 0
Reputation: 395
It's few years, but for windows today as for linux you have the supervisor (pytho based)
supervisor windows based on python
Upvotes: 0
Reputation: 2817
If you want to start a java program without console popup under windows, this should be helpful: In command prompt type the following:
start javaw -jar -Xms1024m -Xmx1024m crafty.jar
If you want you can also write this as a batch file.
Upvotes: 123
Reputation: 61
A batch file is a way of starting the command prompt with the code pre-written, using javaw is a way of open then closing the prompt. Like I said a batch is a commands prompt you can't stop it from opening.
Upvotes: 2
Reputation: 10943
You will always get the command window opening and closing because you are starting it inside a command window or batch script (which launches an implicit command window to run itself). In order not to get a command window you must open the file from "not a command window" i.e. an executable launcher.
Take a look at Launch4j which can run a java program from an exe. It can also hide-away the jar file inside the exe if you like.
http://launch4j.sourceforge.net/
There's a little YouTube clip showing them creating an exe from a jar.
Upvotes: 3
Reputation: 507
start javaw -jar yourjar.jar arg0 arg1
will open the console, but close immediately. it is different from running window .exe.
Upvotes: 4
Reputation: 6784
Create Shortcut
of "%ProgramFiles(x86)%\Java\jre6\bin\javaw.exe", let's name it as Minecraft
, then Minecraft
shortcut. In the Target textbox, append -jar -Xms1024m -Xmx1024m crafty.jar
in the end of javaw.exeStart in
as the folder which contains the crafty.jarDouble-click the Minecraft icon to star the server.
That's all.
Upvotes: 12