The right way to link to tools.jar in a cross-platform way

I am creating a JVM diagnostic tool and I am connecting to the JVM using JMX, the problem I am facing is that I need to be able to load tools.jar in a way that is compatible with all unixes and windows, currently I I use scripts from the gradle-generated startup script to load tools.jar into the classpath, but this method seems to depend on too many factors.

Does anyone know a recommended or elegant way to make this jar accessible on the way to classes without looking blindly, where is it?

+1
java jvm
Sep 02 '14 at 15:12
source share
1 answer

ToolProvider.getSystemToolClassLoader ()

Returns an instance of ClassLoader that tools.jar knows.
If you need the exact path, use

  ((URLClassLoader) ToolProvider.getSystemToolClassLoader()).getURLs() 
+4
Sep 02 '14 at 16:31
source share



All Articles