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

浪尽此生 提交于 2020-01-05 19:27:22

问题


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?


回答1:


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()


来源:https://stackoverflow.com/questions/25626757/correct-way-of-referencing-tools-jar-in-a-cross-platform-way

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!