开发者

JVMTI get name of called Class/File

I tried to read through the whole jvmti documentation and I didn't find a solution for my problem.

I want to get the name of the class/file that is used in the command line to call the program:

java -agentpath:<pathToAgent> <calledJavaProgram>

In upper case I want to get the name of < calledJavaProgram >.

GetSourceFileName(jclass klass,...) gets me only the name of the "klass", that is set in the parameterlist, but since I started the program I even don't know this one ... right?

Are there (other) ways to get this name?

Thx for开发者_运维百科 your help Markus G.


According to the JNI documentation, the JavaVMInitArgs struct is for creating new VMs from native code, so I think that's a red herring. AFAIK there is no API access in either JVMTI or in Java to command line arguments.

There are some things you could do to find out the name of the class with the main method:

  1. Use JNI to call a Java method that works it out.
  2. Use BCI to modify all main methods and do a JNI callback to your agent, the first one to get called is the one you want. This also allows you to get the args[] array.
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜