有没有办法从 Java 程序中隐藏 win32 启动控制台(如果可能,没有 JNI)

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/264687/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-29 11:41:43  来源:igfitidea点击:

Is there a way to the hide win32 launch console from a Java program (if possible without JNI)

javawinapiconsole

提问by Eric Nicolas

You launch a java program from a console (maybe using a .bat script). I don't want the console to remain visible, I want to hide it.

您从控制台启动 Java 程序(可能使用 .bat 脚本)。我不希望控制台保持可见,我想隐藏它。

Is there a simple way to do this ? Without JNI ?

有没有一种简单的方法可以做到这一点?没有JNI?

回答by johnstok

Use javaw.

使用 javaw。

http://java.sun.com/javase/6/docs/tooldocs/windows/java.html

http://java.sun.com/javase/6/docs/tooldocs/windows/java.html

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.

javaw 命令与 java 相同,只是 javaw 没有关联的控制台窗口。当您不希望出现命令提示符窗口时,请使用 javaw。但是,如果由于某种原因启动失败,javaw 启动器将显示一个包含错误信息的对话框。

回答by Manikandan

You can start a java application with start javaw. It will hide the black console window.

您可以使用start javaw. 它将隐藏黑色控制台窗口。

回答by Lukman

This .bat trick works for general programs so I think it should also work for launching java program:

这个 .bat 技巧适用于一般程序,所以我认为它也适用于启动 java 程序:

Call start programinstead of just programin your .bat script

调用start program而不仅仅是program在您的 .bat 脚本中

回答by VonC

You can hide the console by using javaw.exe (java without) instead of using java.exe.

您可以使用 javaw.exe(不含 java)而不是使用 java.exe 来隐藏控制台。

One of the most useful associations to set up is to make *.jar files executable with java.exe. Then you can just type the name of the jar on the command line to start it executing.

要设置的最有用的关联之一是使用 java.exe 使 *.jar 文件可执行。然后,您只需在命令行上键入 jar 的名称即可开始执行。

If you use javaw.exe rather than java.exe you won't see the console output. Watch out, Java installers often associate *.jar files with javaw.exe instead of java.exe, overriding your setting.

如果您使用 javaw.exe 而不是 java.exe,您将看不到控制台输出。请注意,Java 安装程序经常将 *.jar 文件与 javaw.exe 而不是 java.exe 相关联,从而覆盖您的设置。

回答by 1-14x0r

download jsmooth and create your own custom exe in a minute or two. Then just use that exe to launch your java app. You can even get slick and bundle a JRE with your app.

下载 jsmooth 并在一两分钟内创建您自己的自定义 exe。然后只需使用该 exe 启动您的 Java 应用程序。您甚至可以巧妙地将 JRE 与您的应用程序捆绑在一起。

http://jsmooth.sourceforge.net

http://jsmooth.sourceforge.net

回答by t3hnar

In case fo running from but file your script should look like start javaw start javaw -jar ***.jar

如果 fo 从但文件运行,您的脚本应该看起来像 start javaw start javaw -jar ***.jar