aragozin / jvm-tools

Small set of tools for JVM troublshooting, monitoring and profiling.
Apache License 2.0
3.32k stars 518 forks source link

Failed to add tools.jar to classpath #50

Closed 941112341 closed 5 years ago

941112341 commented 5 years ago

Java home points to D:\fuck\jdk1.8 make sure it is not a JRE path Failed to add tools.jar to classpath java.lang.ClassNotFoundException: com.sun.tools.attach.VirtualMachine at java.net.URLClassLoader$1.run(Unknown Source) at java.net.URLClassLoader$1.run(Unknown Source) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(Unknown Source) at java.lang.ClassLoader.loadClass(Unknown Source) at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source) at java.lang.ClassLoader.loadClass(Unknown Source) at org.gridkit.lab.jvm.attach.AttachAPI.(AttachAPI.java:45) at org.gridkit.lab.jvm.attach.AttachManager.(AttachManager.java:73) at org.gridkit.jvmtool.cmd.ProcListCmd$JPS.run(ProcListCmd.java:74) at org.gridkit.jvmtool.cli.CommandLauncher.start(Comman

.... but i can't undertand why?

aragozin commented 5 years ago

sjk is looking for file lib/tools.jar relative to your JDK directory. tools.jar is required to do all JVM discovery and attachment magic.

941112341 commented 5 years ago

thans for your reply.Maybe it's about version.When i upgrade jdk8 to 9,it work well.

aragozin commented 5 years ago

jdk9 doesn't include tools.jar, it includes required classes as part of standard runtime

zhonghuasheng commented 5 years ago
$ java -jar sjk-0.12-SNAPSHOT.jar ttop -p 6344 -n 20 -o CPU
Java home points to C:\Program Files\Java\jre1.8.0_181 make sure it is not a JRE path
Failed to add tools.jar to classpath
java.lang.ClassNotFoundException: com.sun.tools.attach.VirtualMachine
        at java.net.URLClassLoader.findClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at org.gridkit.lab.jvm.attach.AttachAPI.<clinit>(AttachAPI.java:45)
        at org.gridkit.lab.jvm.attach.AttachManager.<clinit>(AttachManager.java:73)
        at org.gridkit.jvmtool.JmxConnectionInfo.getMServer(JmxConnectionInfo.java:78)
        at org.gridkit.jvmtool.cmd.ThreadTopCmd$TTop.run(ThreadTopCmd.java:92)
        at org.gridkit.jvmtool.cli.CommandLauncher.start(CommandLauncher.java:133)
        at org.gridkit.jvmtool.SJK.main(SJK.java:11)
java.lang.NoClassDefFoundError: com/sun/tools/attach/VirtualMachine
        at org.gridkit.lab.jvm.attach.AttachManager$AttachManagerInt.getVmList(AttachManager.java:166)
        at org.gridkit.lab.jvm.attach.AttachManager$AttachManagerInt.getProcesssName(AttachManager.java:155)
        at org.gridkit.lab.jvm.attach.AttachManager$AttachManagerInt.internalGetDetails(AttachManager.java:150)
        at org.gridkit.lab.jvm.attach.AttachManager.getDetails(AttachManager.java:95)
        at org.gridkit.jvmtool.JmxConnectionInfo.getMServer(JmxConnectionInfo.java:78)
        at org.gridkit.jvmtool.cmd.ThreadTopCmd$TTop.run(ThreadTopCmd.java:92)
        at org.gridkit.jvmtool.cli.CommandLauncher.start(CommandLauncher.java:133)
        at org.gridkit.jvmtool.SJK.main(SJK.java:11)
Caused by: java.lang.ClassNotFoundException: com.sun.tools.attach.VirtualMachine
        at java.net.URLClassLoader.findClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        ... 8 more

I am sure I had correct set the JAVA home, and the path is C:\Program Files\Java\jdk1.8.0_181, how can I get this error message? Please help.

aragozin commented 5 years ago

Try where java (which on Linux). tools.jar is searched relative to java binary (not JAVA_HOME variable).

zhonghuasheng commented 5 years ago

Try where java (which on Linux). tools.jar is searched relative to java binary (not JAVA_HOME variable I can successful run above cmd 'java -jar sjk-0.12-SNAPSHOT.jar ttop -p 6344 -n 20 -o CPU' in a Linux server, while failed in Windows server(using git-cmd to execute the cmd). And I am happy pass to install the JDK1.8, not sure what happened.

aragozin commented 5 years ago

Your PATH variable should point JDK/bin not JRE/bin

zhonghuasheng commented 5 years ago

I am also confuse why it print my Java home to a JRE path? Not make sense.

BTW, the guy @941112341 changed to JAVA9 to avoid this.

aragozin commented 5 years ago

please execute where java

zhonghuasheng commented 5 years ago

image

zhonghuasheng commented 5 years ago

I see it point to jdk1.7, not 1.8

aragozin commented 5 years ago

where java should report java.exe from JDK on first line (ideally it should report single line)