views:

1949

answers:

6

If a Java-program is started, it get's in the system process-monitor the name java. Many Java-programs are that way hard to distinguish. So it would be nice, if a way exists, to set the name, that will be shown in the process-monitor. I'm aware that this may work different on different operating-systems.

A simple way would be, if the java-interpreter would support a switch to set the name, like this:

java -processname MyProgram -jar MyProgram

But I couldn't find such a switch, so it is probably non-existant. An API in Java to set the process-name would be also fine.

So, so you have any suggestions?

A: 

That's because Java applications aren't actually executable they're ran by the Java virtual machine which is why java appears in the process monitor, it's the host of your application.

Things like LimeWire however do but I think that's more down to GCJ - http://gcc.gnu.org/java/

Lloyd
+2  A: 

If you want to use a different process name you'll have to create your own binary to launch your Java application using something like JSmooth.

Look at this question for a discussion of creating such binaries.

Dave Webb
+5  A: 

I don't know if this is possible, but you could use a command line tool that comes with the JDK called 'jps'. It's like *nix ps, but just java programs instead. jps -v shows all the arguments you have passed to java.

Also, I have seen people attach a "process name" to their java processes by adding an unused -Dmyprocessname to the args.

omerkudat
Not exactly the answer for that I asked, but exactly the right answer for my problem. Thanks. :-)
Mnementh
+3  A: 

This has been discussed before:

http://stackoverflow.com/questions/882826/how-to-change-the-name-of-a-java-application-process

Thilo
+2  A: 

When I first read this, the idea of changing the process name struck me as impossible. However, according to this ancient thread on the sun forum you can use C++ wrappers around the JVM executable to achieve this.

Though frankly, I wonder what your real problem is, as I'd guess there is a more standard solution then attempting to change the process name.

Tim Bender
If you had to kill your application and had several Java applications running it would be a little hit and miss.
Lloyd
You're right, the jps-command mentioned by omerkudat solve the problem without renaming the processes.
Mnementh
creating a little native JNI wrapper to launch an app is also very easy. For those of us that do Windows deployment, it allows for auto-configuration of the JVM, custom icons, etc... It's really not hard to do.
Kevin Day
A: 

Your best option is something like launch4j http://launch4j.sourceforge.net/

There is a bug logged in the sun bugtracker for this, but it's not high priority http://bugs.sun.com/view_bug.do?bug_id=6299778

Noel Grandin