ajermakovics/jvm-mon

ClassNotFoundException on MacOS/Java 8

fs111 opened this issue · 6 comments

fs111 commented

When I try to run a build of HEAD, I get the following:

$ bin/jvm-mon
Exception in thread "main" java.lang.NoClassDefFoundError: sun/jvmstat/monitor/MonitorException
	at com.jvmtop.view.VMOverviewView.scanForNewVMs(VMOverviewView.java:157)
	at JvmMon.update(JvmMon.java:38)
	at JvmMon.main(JvmMon.java:22)
Caused by: java.lang.ClassNotFoundException: sun.jvmstat.monitor.MonitorException
	at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
	at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
	... 3 more
$ java -version
java version "1.8.0_91"
Java(TM) SE Runtime Environment (build 1.8.0_91-b14)
Java HotSpot(TM) 64-Bit Server VM (build 25.91-b14, mixed mode)
$ uname -a
Darwin somehost.local 15.6.0 Darwin Kernel Version 15.6.0: Mon Jan  9 23:07:29 PST 2017; root:xnu-3248.60.11.2.1~1/RELEASE_X86_64 x86_64

There could be a couple of problems:

  • JAVA_HOME env var is not set
  • JAVA_HOME does not point to a JDK

jvm-mon needs tools.jar to be on the classpath so a quick check is to run stat $JAVA_HOME/lib/tools.jar

@ajermakovics I got the same issue and this is how it looks like the content of my JAVA_HOME

~/t/j/bin ❯❯❯ ls $JAVA_HOME/lib
amd64           visualvm        ct.sym  ir.idl         jconsole.jar  orb.idl       sa-jdi.jar
missioncontrol  ant-javafx.jar  dt.jar  javafx-mx.jar  jexec         packager.jar  tools.jar

Version:

~/t/j/bin ❯❯❯ java -version
java version "1.8.0_121"
Java(TM) SE Runtime Environment (build 1.8.0_121-b13)
Java HotSpot(TM) 64-Bit Server VM (build 25.121-b13, mixed mode)

MonitorException comes from tools.jar so somehow it is not getting added to the classpath

What if you run it directly:

cd jvm-mon-0.1/
java -cp $JAVA_HOME/lib/tools.jar:lib/jvm-mon-0.1.jar JvmMon

The new version (0.2) will print a warning if tools.jar is not found

fs111 commented

The fix to get a valid JAVA_HOME on OS-X is this:

$ export JAVA_HOME=$(/usr/libexec/java_home)

It works now. Thanks!

@ajermakovics worked like a charm, thank you!