Difference between java/javaw/javaws

筅森魡賤 提交于 2019-11-26 15:44:02

See docs for:

  • java command1/javaw command2
    1. The java tool launches a Java application. It does this by starting a Java runtime environment, loading a specified class, and invoking that class's main method.
    2. 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.
  • 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.

    The javaws 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 the javaws 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

Serge Bekenkamp

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.

lfxgroove

from http://publib.boulder.ibm.com/infocenter/javasdk/v6r0/index.jsp?topic=%2Fcom.ibm.java.doc.user.aix32.60%2Fuser%2Fjava.html:

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!