0

I wrote a simple java agent to instrument some activity in java based web applications using the javassist library.

The problem is when I attach my agent to the jp2launcher process I'm getting ClassNotFoundException thrown because it cannot find the javassist.CtBehavior class.

So I tried running a simple local java application just to test my agent to see if it works and it did.

I tried running another test where I only print "hello" to the java console and attach my agent to the web application, and it did work which only tells me that my agent works.

Do any of you have any idea why it cannot find the javassist when attached to the web application? I already set the classpath to point the javassist.jar on my disk.

Thanks

stylo
  • 496
  • 4
  • 12

2 Answers2

1

I had the same issue and had to do a lot of research, until I stumbled on the solution in the Javadoc:

pool.insertClassPath(new LoaderClassPath(loader));

With that you can add the classloader used by the class, this is especially useful when working with java.lang.instrument.ClassFileTransformer.

xresch
  • 11
  • 1
0

You are most likely using a default ClassPool. Javassist represents unloaded classes by parsing the class file for each such class from the class loader. The default class pool does however reference the system class loader. A web application is however executed by a different, application class loader. Therefore, you need to append this class loader to your ClassPool for being able to use it the way you observed it in your unit test.

Rafael Winterhalter
  • 42,759
  • 13
  • 108
  • 192