Recently I noted that some applications are running on javaw (not in java). What is the difference between them and how can I run my Swing application on javaw?
java.exe is the console app while javaw.exe is windows app (console-less). You can't have Console with javaw.exe.
java.exe is the command where it waits for application to complete untill it takes the next command.
javaw.exe is the command which will not wait for the application to complete. you can go ahead with another commands.
The difference is in the subsystem that each executable targets.
java.exe targets the CONSOLE subsystem.
javaw.exe targets the WINDOWS subsystem.
The javaw.exe command is identical to java.exe, except that with javaw.exe there is no associated console window
Related
There is windows process which is actually a java application (java.exe). I need to close it from within other java application (other running .jar) which is probably will also be named as java.exe in windows taskbar.
To do the task we would normally do it this way
Runtime.getRuntime().exec(KILL + serviceName); // where serviceName is a `java.exe`
But there would be some java.exe processes in windows taskbar. So how to find the one I need? In this case it is forum.jar.
Actually this jar was started from .bat file (if it makes any difference) - it is process.bat as it seen in the screenshot.
You could run
wmic process where caption="java.exe" get commandline,description,processid
to get the list of processes and their associated command line like in your screenshot. Then you get the ID of the command you want to kill and kill it with taskkill /pid xxx.
I searched to know the difference between java.exe and javaw.exe. I read through
Difference between Java.exe and Javaw.exe.
There it is stated that java.exe is for console and javaw.exe is for window application.
In some other post it is mentioned that console is not available in javaw.
but I wonder when I run Tomcat server and see its process in process explorer I see javaw.exe even though tomcat is a console application.
The java and javaw commands states
The java and javaw tools start a Java application by starting a JRE and loading a specified class.
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.
In case of Tomcat you won't see Win32 console application running, similarly to launch Eclipse, javaw.exe is used.
Example :
Write the following code :
import javax.swing.*;
public class JavavsJavaw {
private static void renderGUI() {
JFrame jFrame = new JFrame("HelloWorld Swing");
jFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JLabel helloLabel = new JLabel("Hello World!");
jFrame.getContentPane().add(helloLabel);
jFrame.pack();
jFrame.setVisible(true);
}
public static void main(String[] args) {
javax.swing.SwingUtilities.invokeLater(new Runnable() {
public void run() {
renderGUI();
}
});
}
}
Step 1 : C:\>java JavavsJavaw
(the command-line waits for the application response till it closes)
Step 2 : C:\>javaw JavavsJavaw
(the application launches and the command line exits immediately and ready for
next command)
1. java.exe is the command where it waits for application to complete untill it takes the next command, javaw.exe is the command which will not wait for the application to complete. you can go ahead with another commands.
2. java.exe is the console app while javaw.exe is windows app (console-less), The javaw.exe command is identical to java.exe, except that with javaw.exe there is no associated console window
Difference between java.exe and javaw.exe commands is while running java program on windows you might have noticed that they will appear in task manager as either java.exe or javaw.exe, also in JAVA_HOME/bin we see these two java commands java.exe and javaw.exe, do you know difference between java.exe and javaw.exe
Both java.exe and javaw.exe can execute java programs including jar file, only difference is that with java.exe you have a console executed and you need to wait until your java program finishes to run any other command on the other hand in case of javaw.exe no console or window is associated with execution.
you can run your java program either by using java.exe or javaw.exe. Its suggested to use javaw.exe when you don't need command line window to appear. javaw launcher will display in error in a dialog box if execution fails.
In summary main difference between java and javaw command is that with java.exe you will get a command prompt window but with javaw.exe there is no command prompt windows associated.
java.exe pops up a console window. javaw.exe does not.
Both java.exe and javaw.exe can execute java programs including jar file, only difference is that with java.exe you have a console executed and you need to wait until your java program finishes to run any other command on the other hand in case of javaw.exe no console or window is associated with execution.
Main difference between java and javaw command is that with java.exe you will get a command prompt window but with javaw.exe there is no command prompt windows associated.
It depends on how the Tomcat server is run. However, the way of configuring and starting Tomcat is out of the question. I could say that there's different options of doing that. If you starting Tomcat with java it runs like command line application which directs IO to the console. If you run it with javaw then it doesn't directs IO to the console. Many applications and servers has logging capabilities that could direct the output to the console. For this purposed better to use a command line instance of java instead of windows app. There's a reason to run javaw vs java is no logging, debugging messages, no error, stacktraces, exceptions, everything that System.out and System.err produce is visible while you running the application.
In addition to the points stated, it is also can be noted that multi threaded programs can be run with java but javaw can run only single threaded programs!
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:
#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
If you want to start a java program without console popup under windows, this should be helpful:
In command prompt type the following:
start javaw -jar -Xms1024m -Xmx1024m crafty.jar
If you want you can also write this as a batch file.
You should Create Shortcut of "%ProgramFiles(x86)%\Java\jre6\bin\javaw.exe", let's name it as Minecraft, then
edit the Properties of Minecraft shortcut. In the Target textbox, append -jar -Xms1024m -Xmx1024m crafty.jar in the end of javaw.exe
change the Start in as the folder which contains the crafty.jar
Double-click the Minecraft icon to star the server.
That's all.
Create a .bat file with
start javaw -jar yourjar.jar arg0 arg1
start javaw -jar yourjar.jar arg0 arg1
will open the console, but close immediately. it is different from running window .exe.
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.
http://launch4j.sourceforge.net/
There's a little YouTube clip showing them creating an exe from a jar.
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.
It's few years, but for windows today as for linux you have the supervisor (pytho based)
supervisor windows based on python
I would like to know if there is a way to execute the "java.exe" as a background process (silent mode execution)
Ex: java -cp . MyClass arg1
I want to run the above statement as a background process , without opening command window
Under Windows, use javaw.exe instead of java.exe. See here for link, relevant bit copied here:
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.
Use
javaw -cp . MyClass arg1
(assuming you're on MS windows)
If you're looking at services rather then applications then have a look at 'service wrappers'
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.
Is there a simple way to do this ? Without JNI ?
Use javaw.
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.
You can start a java application with start javaw. It will hide the black console window.
This .bat trick works for general programs so I think it should also work for launching java program:
Call start program instead of just program in your .bat script
You can hide the console by using javaw.exe (java without) instead of using 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.
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.
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.
http://jsmooth.sourceforge.net
In case fo running from but file your script should look like
start javaw start javaw -jar ***.jar
Note, that you may need running javaw.exe by providing full path to the file, that may need adding quotes " in case there are spaces in the path. The quotes will trigger recognition of them as "title"-argument for the "start" command.
So, use following correct format:
start "MyTitle" "c:\Program Files (x86)\Java\jdk1.8.0_202\bin\javaw.exe" -jar myApp.jar
where title can be empty if needed