在没有控制台的情况下启动java程序

时间:2021-11-12 02:37:41

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:

我正在尝试将此GUI mod用于Minecraft服务器。我写了一个批处理文件,所以服务器可以启动更多的RAM。当我只运行.jar文件时,没有打开命令窗口,它运行得很好(当然大约有256mb ram)我在线阅读javaw启动一个没有命令行控制台的jar文件。但是当我使用javaw时,命令控制台会打开,但是当我关闭它时程序仍然打开。这是我的批处理文件:

@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

我也不了解java,所以请尽量清楚。谢谢

6 个解决方案

#1


88  

If you want to start a java program without console popup under windows, this should be helpful: In command prompt type the following:

如果你想在Windows下启动没有控制台弹出窗口的java程序,这应该会有所帮助:在命令提示符下键入以下内容:

start javaw -jar -Xms1024m -Xmx1024m crafty.jar

启动javaw -jar -Xms1024m -Xmx1024m crafty.jar

If you want you can also write this as a batch file.

如果您愿意,也可以将其写为批处理文件。

#2


10  

  • You should Create Shortcut of "%ProgramFiles(x86)%\Java\jre6\bin\javaw.exe", let's name it as Minecraft, then
  • 您应该创建“%ProgramFiles(x86)%\ Java \ jre6 \ bin \ javaw.exe”的快捷方式,让我们将其命名为Minecraft,然后
  • edit the Properties of Minecraft shortcut. In the Target textbox, append -jar -Xms1024m -Xmx1024m crafty.jar in the end of javaw.exe
  • 编辑Minecraft的属性快捷方式。在Tar​​get文本框中,在javaw.exe的末尾追加-jar -Xms1024m -Xmx1024m crafty.jar
  • change the Start in as the folder which contains the crafty.jar
  • 将“开始”更改为包含crafty.jar的文件夹

Double-click the Minecraft icon to star the server.

双击Minecraft图标为服务器加注星标。

That's all.

就这样。

#3


7  

Create a .bat file with

用。创建一个.bat文件

start javaw -jar yourjar.jar arg0 arg1

#4


3  

start javaw -jar yourjar.jar arg0 arg1

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

将打开控制台,但立即关闭。它与运行窗口.exe不同。

#5


2  

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.

看看Launch4j,它可以从exe运行java程序。如果你愿意,它还可以隐藏exe文件中的jar文件。

http://launch4j.sourceforge.net/

http://launch4j.sourceforge.net/

There's a little YouTube clip showing them creating an exe from a jar.

有一个YouTube剪辑显示他们从jar创建一个exe。

#6


0  

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.

批处理文件是一种使用预编写的代码启动命令提示符的方法,使用javaw是一种打开然后关闭提示的方法。就像我说批处理是一个命令提示你不能阻止它打开。

#1


88  

If you want to start a java program without console popup under windows, this should be helpful: In command prompt type the following:

如果你想在Windows下启动没有控制台弹出窗口的java程序,这应该会有所帮助:在命令提示符下键入以下内容:

start javaw -jar -Xms1024m -Xmx1024m crafty.jar

启动javaw -jar -Xms1024m -Xmx1024m crafty.jar

If you want you can also write this as a batch file.

如果您愿意,也可以将其写为批处理文件。

#2


10  

  • You should Create Shortcut of "%ProgramFiles(x86)%\Java\jre6\bin\javaw.exe", let's name it as Minecraft, then
  • 您应该创建“%ProgramFiles(x86)%\ Java \ jre6 \ bin \ javaw.exe”的快捷方式,让我们将其命名为Minecraft,然后
  • edit the Properties of Minecraft shortcut. In the Target textbox, append -jar -Xms1024m -Xmx1024m crafty.jar in the end of javaw.exe
  • 编辑Minecraft的属性快捷方式。在Tar​​get文本框中,在javaw.exe的末尾追加-jar -Xms1024m -Xmx1024m crafty.jar
  • change the Start in as the folder which contains the crafty.jar
  • 将“开始”更改为包含crafty.jar的文件夹

Double-click the Minecraft icon to star the server.

双击Minecraft图标为服务器加注星标。

That's all.

就这样。

#3


7  

Create a .bat file with

用。创建一个.bat文件

start javaw -jar yourjar.jar arg0 arg1

#4


3  

start javaw -jar yourjar.jar arg0 arg1

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

将打开控制台,但立即关闭。它与运行窗口.exe不同。

#5


2  

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.

看看Launch4j,它可以从exe运行java程序。如果你愿意,它还可以隐藏exe文件中的jar文件。

http://launch4j.sourceforge.net/

http://launch4j.sourceforge.net/

There's a little YouTube clip showing them creating an exe from a jar.

有一个YouTube剪辑显示他们从jar创建一个exe。

#6


0  

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.

批处理文件是一种使用预编写的代码启动命令提示符的方法,使用javaw是一种打开然后关闭提示的方法。就像我说批处理是一个命令提示你不能阻止它打开。