简体   繁体   中英

ClassNotFoundException with java agent (-javaagent:jarpath)

The root of my problem is that I'm trying to use the SizeOf sourceforge project from a web application deployed on JBoss AS7 and getting a ClassNotFoundException for net.sourceforge.sizeof.SizeOf . I added -javaagent:/path_to_jar/SizeOf.jar to the server's JAVA_OPTS and see the System.out.println from the premain method on server startup (JAVAGENT: call premain instrumentation for class SizeOf). However, when I try to call SizeOf.sizeOf(obj) from my servlet's doGet method, the application fails with the aforementioned ClassNotFoundException .

If anyone can tell me how to get this working with JBoss AS7, that would be helpful (I have it working in an Eclipse run configuration -- the equivalent of running from the command line). What I would really like to do, above and beyond that, is to understand how classloading works for Java Agents. The best documentation I've been able to find is in the offical JVM docs , and that's pretty sparse. All it says about classloading is that the Premain-Class will be loaded by the system classloader. I saw a blog post that suggested that the jar didn't need to be placed on the classpath, since the -javaagent JVM argument would take care of that, so it would appear that I shouldn't have to add the SizeOf jar as a AS7 module. Am I missing something?

Need to do the following:

  • Create a module for agent: create folder modules/net/sourceforge/sizeof/main and add sizeof.jar and a module.xml
  • Add module to boot config: add JBOSS_MODULES_SYSTEM_PKGS="net.sourceforge.sizeof" to bin/standalone.conf
  • Also in bin/standalone.conf, append -javaageent:../modules/net/sourceforge/sizeof/main/sizeof.jar to JAVA_OPTS

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM