Im developing a simple console application using java. I want to display currently running jar files in my system. The following code is displaying all running process window.
try {
String cmds[] = { "cmd", "/c", "tasklist" };
Process myProcess = Runtime.getRuntime().exec(cmds);
BufferedReader stdout = new BufferedReader(new InputStreamReader(
myProcess.getInputStream()));
String line = stdout.readLine();
File file = new File("writer.txt");
writer = new BufferedWriter(new FileWriter(file));
while (line != null) {
writer.write(line);
writer.write("\n");
System.out.println(line);
line = stdout.readLine();
}
writer.close();
} catch (Exception e) {// Catch exception if any
System.err.println("Error: " + e.getMessage());
}
Im used
`String cmds[] = { "cmd", "/c", "jps" };`
But its not displayed the process. Please anyone give the suggestions. Thanks n advance.
The only thing you actually can see are running java virtual machines but the operating system can’t see what threads are running inside the jvms.
A ‘jar’ file is not an executable file. It is nothing but a java library with an extra entry in the libraries manifest, that names one class with a ‘main’ methods. So if you start java with the jar option and pass such a jar, the virtual machine will use this method to start the main thread.
But we still can have several additional threads running in the same virtual machine and each thread could fit in the concept of an application.
For
jps:and
So if the virtual machine is not instrumented, then jps will not report anything (and I doubt that it can list the jar files that are on the classpaths or that have been used to load classes so far).