java 使用命令行参数启动 .jar 文件(但没有控制台窗口)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/711370/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Launch .jar files with command line arguments (but with no console window)
提问by Virat Kadaru
I have to do a demo of an application, the application has a server.jar and client.jar. Both have command line arguments and are executable. I need to launch two instances of server.jar and two instances of client.jar.
我要做一个应用的demo,应用有server.jar和client.jar。两者都有命令行参数并且是可执行的。我需要启动 server.jar 的两个实例和 client.jar 的两个实例。
I thought that using a batch file was the way to go, but, the batch file executes the first command (i.e. >server.bat [argument1] [argument2]) and does not do anything else unless I close the first instance, in which case it then runs the 2nd command. And also the I do not want a blank console window to open (or be minimized)
我认为使用批处理文件是可行的方法,但是,批处理文件执行第一个命令(即 >server.bat [argument1] [argument2])并且不执行任何其他操作,除非我关闭第一个实例,其中如果它然后运行第二个命令。而且我不希望打开(或最小化)一个空白的控制台窗口
What I really need is a batch script that will just launch these apps without any console windows and launch all instances that I need.
我真正需要的是一个批处理脚本,它可以在没有任何控制台窗口的情况下启动这些应用程序并启动我需要的所有实例。
Thanks in Advance!
提前致谢!
EDIT:
编辑:
javaw:
爪哇:
works if I type the command into the console window individually. If I put the same in the batch file, it will behave as before. Console window opens, one instance starts (whichever was first) and it does not proceed further unless I close the application in which case it runs the 2nd command. I want it to run all commands silently
如果我单独在控制台窗口中键入命令,则可以工作。如果我将相同的内容放在批处理文件中,它将像以前一样运行。控制台窗口打开,一个实例启动(以先到者为准),除非我关闭应用程序,否则它不会继续进行,在这种情况下它会运行第二个命令。我希望它静默运行所有命令
采纳答案by Virat Kadaru
Found the solution, below is the contents of my batch file
找到解决方案,下面是我的批处理文件的内容
@echo off
start /B server.jar [arg1] [arg2]
start /B server.jar [arg3] [arg4]
start /B client.jar [arg5]
start /B client.jar [arg6]
@echo on
this opens, runs all the commands and closes the window, does not wait for the command to finish.
这将打开,运行所有命令并关闭窗口,不等待命令完成。
I am still not sure how to prevent the window from opening completely.
我仍然不确定如何防止窗户完全打开。
回答by McDowell
Try:
尝试:
javaw <args>
回答by Tiago Lopes da Costa
Alright after tring and cring, here goes my soluction
好吧,在反复无常之后,这是我的解决方案
@echo off
start /B javaw -jar -Xms16m -Xmx512m client.jar
@echo on
I hope it will be usefull for somebody.
我希望它对某人有用。

