Installing OpenNMS fails with ClassNotFoundException: com.sun.tools.attach.AttachNotSupportedException

installation
troubleshooting

#1

Problem

When you try to install OpenNMS you get an exception during the initialisation of the database with the following content:

INFO 12/7/18 1:45 PM:liquibase: Successfully released change log lock
java.lang.reflect.InvocationTargetException
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at org.opennms.bootstrap.Bootstrap$4.run(Bootstrap.java:525)
	at java.lang.Thread.run(Thread.java:748)
Caused by: java.lang.NoClassDefFoundError: com/sun/tools/attach/AttachNotSupportedException
	at org.opennms.netmgt.vmmgr.ControllerUtils.getController(ControllerUtils.java:48)
	at org.opennms.upgrade.support.Upgrade.isOpennmsRunning(Upgrade.java:110)
	at org.opennms.upgrade.support.Upgrade.execute(Upgrade.java:233)
	at org.opennms.upgrade.support.Upgrade.main(Upgrade.java:266)
	... 6 more
Caused by: java.lang.ClassNotFoundException: com.sun.tools.attach.AttachNotSupportedException
	at java.net.URLClassLoader.findClass(URLClassLoader.java:382)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
	at java.net.FactoryURLClassLoader.loadClass(URLClassLoader.java:817)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
	... 10 more

If you run from the installer script the output looks like this.

PostgreSQL initialize                 ... OK
PostgreSQL set auth from ident to md5 ... OK
Start PostgreSQL database             ... OK
PostgreSQL systemd enable             ... OK

Enter database username: mydb
Enter database password:

Generate OpenNMS data source config   ... OK
Initialize OpenNMS                    ... FAILED

Diagnosis

When you run the installer scripts you will find this exception in the bootstrap.log file. Check if you have a “javac” binary available and it is in major version 8.

You can check which Java environment is used from OpenNMS and the installer when you run:

${OPENNMS_HOME}/bin/runjava -c

You should be able the javac binary in the major version 8 is available on your system. You can test it with:

javac -version

You can check the installed Java versions:

CentOS/RHEL:

yum list installed | grep java

modern Debian/Ubuntu:

apt list --installed java

older Debian/Ubuntu:

dpkg --get-selections | grep -v deinstall | grep openjdk

Cause

OpenNMS requires to have a Java Development Kit. A Java Runtime Environment is not enough. During the installation OpenNMS checks a general Java dependency. When you install on a Server with a GUI, it installs automatically a Java Runtime Environment which satisfies this dependency and OpenNMS will not change your Java environment and uses the existing one.

Resolution

Install a Java Development Kit and make sure it is used from the OpenNMS installer. The Java Development Kit for OpenJDK is named java-1.8.0-openjdk-devel and on Ubuntu/Debian openjdk-8-jdk. If you have multiple Java environments installed you can run ${OPENNMS_HOME}/bin/runjava -S <JRE path> to set the appropriate Java environment and run the installer again.