What is the correct way to attach to IBM's J9VM using the Java Attach API?
I am trying the following (with having the JDK's tools.jar in my classpath):
private static final J9AttachProvider ATTACH_PROVIDER = new J9AttachProvider();
...snip...
String pid = getPIDofRunningVM();
Constructor<J9VirtualMachine> constructor = J9VirtualMachine.class.getConstructor(new Class[]{AttachProvider.class, String.class
});
constructor.setAccessible(true);
J9VirtualMachine virtualMachine = constructor.newInstance(new Object[]{ATTACH_PROVIDER, pid});
I also tried doing it without the use of reflection but i keep getting
Exception in thread "main" java.lang.reflect.InvocationTargetException
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:44)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:516)
at de.test.Test.gogo(Test.java:34)
at de.teset.Test.main(Test.java:26)
Caused by: java.lang.IllegalAccessError
at ibm.tools.attach.J9VirtualMachine.<init>(J9VirtualMachine.java:24)
... 6 more
Does anybody know what the proper way to do this is?