Skip to main content

error : com.sun.tools.attach.AgentInitializationException: Agent JAR loaded but agent failed to initialize

Please note these java.net forums are being decommissioned and use the new and improved forums at https://community.oracle.com/community/java.
1 reply [Last post]
michelqa
Offline
Joined: 2011-12-07
Points: 0

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

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
michelqa
Offline
Joined: 2011-12-07
Points: 0

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