Fwd: How to get the "main" class?
Krystal Mok
rednaxelafx at gmail.com
Tue Mar 13 21:14:59 PDT 2012
Oops, I forgot to "reply all" again...
---------- Forwarded message ----------
From: Krystal Mok <rednaxelafx at gmail.com>
Date: Wed, Mar 14, 2012 at 2:18 AM
Subject: Re: How to get the "main" class?
To: Eric Caspole <eric.caspole at amd.com>
Hi Eric,
Within the Java program itself:
There's a "sun.java.command" system property that will give you the Java
command line. The substring up to the first space (or the end of the
string, whichever comes first) is the name of the main class.
JVMTI agents could used this.
>From the outside of the Java program:
I guess the easiest way the get the name of the main class is to follow how
Jps does it, through the jvmstat API. [1][2]
Get the StringMonitor by the name "sun.rt.javaCommand", that will give you
the Java command line. The rest is the same as above.
HTH,
- Kris
[1]:
http://hg.openjdk.java.net/jdk8/jdk8/jdk/file/tip/src/share/classes/sun/tools/jps/Jps.java
[2]:
http://hg.openjdk.java.net/jdk8/jdk8/jdk/file/tip/src/share/classes/sun/jvmstat/monitor/MonitoredVmUtil.java
On Wed, Mar 14, 2012 at 1:49 AM, Eric Caspole <eric.caspole at amd.com> wrote:
> Is there a way via JVMTI or system property or anything to get the "main"
> class name of a Java application? We could use this to report the app name
> in a nicer way, rather than concatenating the whole java command line, for
> example.
> Thanks,
> Eric
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.openjdk.java.net/pipermail/hotspot-runtime-dev/attachments/20120314/cafaffbc/attachment.html
More information about the hotspot-runtime-dev
mailing list