Unable to start javaagent without errors

I am trying to create a simple Java Agent program before I implement the real thing. I cannot get it to work. Obviously I have some kind of configuration or class issue. No amount of looking and trying led to my problem.

If I run:

java -cp./demoAgent.jar -javaagent: ./ demoAgent.jar com.kingtigerbooks.demoMod.Main

I am getting the following error:

Exception in thread "main" java.lang.ClassNotFoundException: com.kingtigerbooks.demoAgent.Agent
    at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
    at sun.instrument.InstrumentationImpl.loadClassAndStartAgent(InstrumentationImpl.java:280)
    at sun.instrument.InstrumentationImpl.loadClassAndCallPremain(InstrumentationImpl.java:338)
FATAL ERROR in native method: processing of -javaagent failed
Abort trap

      

I am running this on my Mac. The agent jar file is in the current directory. The manifest for the jar file looks like this:

Manifest-Version: 1.0
Premain-class: com.kingtigerbooks.demoAgent.Agent
Can-Redefine-Classes: true

      

If it smells like a class problem, but as you can see I have included the jar in the classpath. Any help would be greatly appreciated. This is a very simple project.

+3


source to share


2 answers


The problem has been resolved. I had a file with bad jars. The agent jar file did not contain the agent class. By creating the correct jar file and putting the full path to the jar in the javaagent parameter it all works.



+4


source


when you start the agent you are not adding the agent jar to the normal classpath.



as a side note, you can add -verbose:class

to the command line to get information about the class loading process.

+2


source







All Articles