以跨平台方式引用tools.jar的正确方法(Correct way of referencing tools.jar in a cross

编程入门 行业动态 更新时间:2024-10-23 08:35:07
以跨平台方式引用tools.jar的正确方法(Correct way of referencing tools.jar in a cross-platform way)

我正在构建一个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()

更多推荐

本文发布于:2023-07-23 00:51:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1225198.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:正确   方式   方法   平台   referencing

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!