58

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

jcomeau_ictx
  • 37,688
  • 6
  • 92
  • 107
tuxxi
  • 681
  • 1
  • 5
  • 4
  • 1
    Maybe, the app is programmed to close the GUI frame only, not the whole process itself in its `setDefaultCloseOperation(op)` call. http://download.oracle.com/javase/1.4.2/docs/api/javax/swing/JFrame.html#setDefaultCloseOperation Or, `The javaw command is identical to java, except that with javaw there is no associated console window. Use javaw when you don't want a command prompt window to appear. The javaw launcher will, however, display a dialog box with error information if a launch fails for some reason` – eee Apr 19 '11 at 02:16
  • Shouldn't this be on gaming.stackexchange.com? – Blessed Geek Apr 19 '11 at 02:30
  • @Blessed Geek: no. Super User maybe. But now there are three close-votes for off-topic, so it cannot be migrated anymore. – Joey Apr 19 '11 at 07:32
  • @tuxxi I guess u should accept an answer if you are still able to read this comment. – guness Feb 20 '13 at 11:57

7 Answers7

121

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.

cheffe
  • 9,345
  • 2
  • 46
  • 57
RollingBoy
  • 2,767
  • 1
  • 14
  • 8
11
  • You should Create Shortcut of "%ProgramFiles(x86)%\Java\jre6\bin\javaw.exe", let's name it as Minecraft, then
  • edit the Properties of Minecraft shortcut. In the Target textbox, append -jar -Xms1024m -Xmx1024m crafty.jar in the end of javaw.exe
  • change the Start in as the folder which contains the crafty.jar

Double-click the Minecraft icon to star the server.

That's all.

Yi Zhao
  • 6,768
  • 1
  • 18
  • 18
  • 1
    You can also do this with the EXE version: start javaw -jar -Xms1024m -Xmx1024m Minecraft.exe – StormFoo Sep 17 '12 at 11:58
  • 1
    one has to use javaw.exe, not java.exe! – jan Feb 25 '15 at 09:40
  • Some Applications, especially java Applications, have a large number of start-up command-line options which will exceed the 260 character limit for the shortcut "Target" field. In this case, create an environment variable with all the options in it and use the variable in the "target" field. – Mirko Klemm Aug 28 '18 at 08:51
9

Create a .bat file with

start javaw -jar yourjar.jar arg0 arg1
Nans
  • 146
  • 2
  • 4
3
start javaw -jar yourjar.jar arg0 arg1

will open the console, but close immediately. it is different from running window .exe.

Dave
  • 487
  • 1
  • 6
  • 19
3

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.

David Newcomb
  • 10,639
  • 3
  • 49
  • 62
2

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.

Coder Kid
  • 61
  • 1
  • 1
  • 6
0

It's few years, but for windows today as for linux you have the supervisor (pytho based)

supervisor windows based on python

developer learn999
  • 365
  • 1
  • 4
  • 17