以跨平台方式引用tools.jar的正确方法 [英] Correct way of referencing tools.jar in a cross-platform way
问题描述
我正在构建一个JVM诊断工具,并且正在使用JMX连接到JVM,我在这里面临的问题是我需要能够以一种在整个Unix和Windows,目前我正在使用gradle生成的运行脚本将tools.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.
没有人知道推荐的或优雅的方法来使此jar在类路径上可用,而没有盲目地猜测它在哪里吗?
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
实例.
如果您想要确切的路径,请使用
This returns the instance of ClassLoader
that is aware of tools.jar
.
If you'd like the exact path, use
((URLClassLoader) ToolProvider.getSystemToolClassLoader()).getURLs()
这篇关于以跨平台方式引用tools.jar的正确方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!