Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unable to execute javaagent in intellij - getting ClassNotFoundException for my agent class

I'm getting this message in the following scenario:

java.lang.ClassNotFoundException: agents.MemoryAgent

I've bundled, by hand following this link, a java agent class into a jar. For the run/debug configuration I've copied a working entry and added VM arguments.

I've tried both of these (the constant arguments are carried over from the copied config)

-javaagent:agent.jar -Xms256m -Xmx1024m -Djava.net.preferIPv4Stack=true

And

-javaagent:agent.jar -cp . -Xms256m -Xmx1024m -Djava.net.preferIPv4Stack=true

NOTE: pseudonym class used here, real class exists enter image description here

I've tried putting the agent.jar file into the 'Working Directory' specified above, as well as the 'Project compiler output' directory specified in the project structure/setting dialog.

The entire contents of my manifest.txt file:

Premain-Class: agents.MemoryAgent

Which yields in the META-INF\MANIFEST.MF file when extracted:

Manifest-Version: 1.0 Created-By: 1.6.0 (Sun Microsystems Inc.) Premain-Class: agents.MemoryAgent

I have verified that the class' path matches that used in the jar and class files.


I'm using:

  • java version "1.7.0_25"
  • Intellij12.1

Why can't it find the class?

In the screenshot a field is titled 'Use classpath of module', but I could not find anywhere that this is defined. Is that relevant?

like image 971
rediVider Avatar asked Feb 04 '26 09:02

rediVider


1 Answers

IDEA will try to find the jar that you have specified in -javaagent, (agent.jar in your case) in the working directory (shown in the above screen). Copying the jar to your "Working Directory" as shown in the above UI will fix the issue. So, for your case, copy the agent.jar to "E:\Autre\Projects\JetBrains"

like image 176
aileronajay Avatar answered Feb 07 '26 01:02

aileronajay



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!