I use the Java Attach API (part of tools.jar) to attach to a running Java process and close it internally.
It works great on Windows. However, when you try to execute attach code while working on linux, I get java.lang.NoClassDefFoundError
with the following stack trace for the reason ...
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 am using Maven and so far I have this section to enable 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>
In particular, the value of $ {java.home} is evaluated in jre, but even if I change it to the direct path to jdk, the problem will be the same.
I am very confused ...
source share