简体   繁体   English

以跨平台方式引用tools.jar的正确方法

[英]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. 我正在构建一个JVM诊断工具,并且正在使用JMX连接到JVM,我现在面临的问题是我需要能够以一种在整个Unix和Windows兼容的方式加载tools.jar。我正在使用gradle生成的运行脚本将tools.jar加载到类路径中,但是似乎此方法取决于太多因素。

Does anyone knows the recommended or elegant way of making this jar available on the classpath without actually blindly guessing where is it? 有谁知道推荐的或优雅的方法来使此jar在类路径上可用,而又没有盲目地猜测它在哪里?

ToolProvider.getSystemToolClassLoader() ToolProvider.getSystemToolClassLoader()

This returns the instance of ClassLoader that is aware of tools.jar . 这将返回知道tools.jarClassLoader实例。
If you'd like the exact path, use 如果您想要确切的路径,请使用

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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