我正在构建一个JVM诊断工具,我正在使用JMX连接到JVM,我面临的问题是我需要能够以一种兼容整个unix和windows的方式加载tools.jar,目前我正在使用gradle生成的运行脚本将tools.jar加载到类路径中,但似乎这种方法取决于太多因素。
有没有人知道推荐或优雅的方法在类路径上提供这个jar而不是真的盲目地猜测它在哪里?
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()
这将返回知道tools.jar的ClassLoader实例。 如果您想要确切的路径,请使用
((URLClassLoader) ToolProvider.getSystemToolClassLoader()).getURLs()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()更多推荐
发布评论