Jun 14, 2013

[Solved] NoClassDefFoundError, cannot find VirtualMachine when using HotThread

Posted Jun 14, 2013
I got a NoClassDefFoundError when trying to execute HotThread.jar in Cent OS Linux using java -jar command, seems it cannot find com/sun/tools/attach/VirtualMachine which is part of tools.jar.


[root@ALFSYSTEST4-VM bin]# ./java -jar /home/samba/HotThread.jar 3223
Exception in thread "main" java.lang.NoClassDefFoundError: com/sun/tools/attach/VirtualMachine
        at hotthread.Main.main(Main.java:52)
Caused by: java.lang.ClassNotFoundException: com.sun.tools.attach.VirtualMachine
        at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:303)
        at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
        at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:316)
        ... 1 more


The solution is to just use the java -classpath approach and load the two libraries then execute the HotThread program:

java -classpath "/opt/jdk1.6/lib/tools.jar:/home/samba/HotThread.jar" hotthread.Main 3223



No comments:

Post a Comment