Is there a way to attach to an already running JVM?
For example, in JNI you can use JNI_CreateJavaVM
to create a VM and run a jar and inspect all its classes..
However, if the jar is already running, I cannot find a way to attach to its JVM and communicate with its classes or get its env
pointer..
Another problem is that if the jar loads my native library (.dll) and I want to create a JVM inside the .dll, I cannot.. Nor can I attach the jar's current JVM either without the jar calling my function..
Example on the Java side:
class Foo
{
static {loadLibrary("Foo")}
}
on the C++ side:
void Foo()
{
//CreateJVM
//Attach to the current process..
//Call function from the jar that loaded me.
}
This cannot be done without the jar calling Foo
first.
Any ideas? Is there no way to get the current JVM or to attach to it or an external jvm instance?