I am wondering, what's the difference between java
/javaw
/javaws
? I found under windows, most of Java is started using javaw
.
See docs for:
java
command1/javaw
command2- The
java
tool launches a Java application. It does this by starting a Java runtime environment, loading a specified class, and invoking that class'smain
method. - The
javaw
command is identical tojava
, except that withjavaw
there is no associated console window. Usejavaw
when you don't want a command prompt window to appear.
- The
javaws
command, the "Java Web Start command"The
javaws
command launches Java Web Start, which is the reference implementation of the Java Network Launching Protocol (JNLP). Java Web Start launches Java applications/applets hosted on a network.
If a JNLP file is specified,javaws
will launch the Java application/applet specified in the JNLP file.
Thejavaws
launcher has a set of options that are supported in the current release. However, the options may be removed in a future release.See also JDK 9 Release Notes Deprecated APIs, Features, and Options:
Java Deployment Technologies are deprecated and will be removed in a future release
Java Applet and WebStart functionality, including the Applet API, The Java plug-in, the Java Applet Viewer, JNLP and Java Web Start including thejavaws
tool are all deprecated in JDK 9 and will be removed in a future release.
java: java application executor which is associated with a console to display output/errors
javaw: (java windowed) application executor not associated with console. So no display of output/errors. Can be used to silently push the output/errors to text files. Mostly used to launch GUI based application
javaws: (java web start) to download and run the distributed web applications. again No console is associated.
All are part of JRE and use same JVM
java.exe is associated with the console, whereas javaw.exe doesn't have any such association. So, when java.exe is run, it automatically opens a command prompt window where output and error streams are shown.
The javaw command is identical to java, except that javaw has no associated console window. Use javaw when you do not want a command prompt window to be displayed. The javaw launcher displays a window with error information if it fails.
And javaws is for java web start applications, applets or something like that i would suspect
I have checked that the output redirection works with javaw:
javaw -cp ... mypath.MyClass ... arguments 1>log.txt 2>err.txt
It means, if the java application prints out anything via System.out or System.err, it is written in that files, as also with using java (without w). Especially on starting java the JRE may write starting errors (class not found) on the error output pipe. In this respect it is essential to know about errors. I suggest to use the console redirection in any case if javaw is invoked.
In opposite if you use
start java .... 1>log.txt 2>err.txt
With the windows console start command, the console output redirection does NOT work with java and with javaw too.
Explaination, why it is so: I think that javaw opens an internal process on the OS (adequate using the java.lang.Process class), and transfers a known output redirection to this process. If no redirection is given on command line, nothing is redirect and the internal started process for javaw has no console outputs. The behavior for java.lang.Process is similar. The virtual machine may use this internal feauture for javaw too.
If you use 'start', the windows console creates a new process for windows to execute the command after start, but this mechanism does not use a given redirection for the started sub process, unfortunately.
来源:https://stackoverflow.com/questions/8194713/difference-between-java-javaw-javaws