I've been using the Java Attach API (part of tools.jar) to attach to a running java process, and shut it down from within.
It works perfectly on Windows. However when trying to actually execute the attach code when running on linux I get a java.lang.NoClassDefFoundError
with the following stack trace for the cause...
java.lang.ClassNotFoundException:com.sun.tools.attach.VirtualMachine...
java.net.URLClassLoader$1.run(URLClassLoader.java:202)
java.security.AccessController.doPrivileged(Native Method)
java.net.URLClassLoader.findClass(URLClassLoader.java:190)
java.lang.ClassLoader.loadClass(ClassLoader.java:306)
sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
java.lang.ClassLoader.loadClass(ClassLoader.java:247)
I'm using Maven and so far I have this section, in order to include tools.jar.
<dependency>
<groupId>com.sun</groupId>
<artifactId>tools</artifactId>
<version>1.4.2</version>
<scope>system</scope>
<systemPath>${java.home}/../lib/tools.jar</systemPath>
</dependency>
Notably the ${java.home} evaluates to the jre but even if I change it to a direct path to the jdk, the issue is the same.
I'm pretty stumped...
system
scope implies the jar will be provided by the container (which happens in eclipse, but not when simply running via java -jar). Experimenting withinstall:install-file
goal so that the required jar is placed in the repo at build time. – Denotative