error : com.sun.tools.attach.AgentInitializationException: Agent JAR loaded but agent failed to initialize
We are trying to make a **simple** hello World agent class but the agent cannot be initialized
ex:
====
VirtualMachine vm = VirtualMachine.attach("4520"); //PID of the tested application is hardcoded
String agent = "c:\\temp\\MYAgent.jar";
vm.loadAgent(agent, null);
ex: (the AgentClass)
=====================
import java.lang.instrument.*;
public class MYAgent {
public static void premain(String args, Instrumentation inst) throws Exception {
JOptionPane.showMessageDialog(null, "Hello from premain agent!");
}
public static void agentmain(String args, Instrumentation inst) throws Exception {
JOptionPane.showMessageDialog(null, "Hello from premain agent!");
}
}
The manifest look like this :
Manifest-Version: 1.0
Premain-Class: Com.MyAgent
Agent-Class: Com.MyAgent
Created-By: 1.6.0_06 (Sun Microsystems Inc.)
Note : I tried with premain, agentmain etc... any possible way and it's not working
We always get the error : com.sun.tools.attach.AgentInitializationException: Agent JAR loaded but agent failed to initialize
How the hell the loaded agent jar can be correctly initialized ??? I know there is many possible cause but we tried almost anything
Thanks
Michel





We finally found the problem....we need to restart the application (the one to "inject" the agent) or the old jar (from a previous compilation) will be used instead.
I was not really comfortable with java packaging and even java in general so I had to learn a little bit more to make it work
Thanks again
Michel