简体   繁体   中英

Correct way of referencing tools.jar in a cross-platform way

I'm building a JVM diagnostics tool and I'm connecting to the JVMs using JMX, the Issue I'm facing here is that I need to be able to load tools.jar in a way that is compatible throughout unixes and windows, currently I'm using the gradle-generated run scripts to load the tools.jar to the classpath but it seems this method depends on too many factors.

Does anyone knows the recommended or elegant way of making this jar available on the classpath without actually blindly guessing where is it?

ToolProvider.getSystemToolClassLoader()

This returns the instance of ClassLoader that is aware of tools.jar .
If you'd like the exact path, use

    ((URLClassLoader) ToolProvider.getSystemToolClassLoader()).getURLs()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM