Java Attach API:动态更改java.library.path [英] Java Attach API: changing java.library.path dynamically

查看:198
本文介绍了Java Attach API:动态更改java.library.path的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的Windows机器上使用com.sun.tools.attach API时,在拨打电话时出现以下错误

When using the com.sun.tools.attach API on my Windows machine, I get the following error when making a call to

VirtualMachine.list()

java.lang.UnsatisfiedLinkError:java中没有附件.library.path

原因是缺少attach.dll。 attach.dll位于 $ JRE / bin / 中。使用 -Djava.library.path = [attach.dll的目录] 启动我的Java程序时,一切都没有错误输出。

The reason is the missing attach.dll. The attach.dll is located in $JRE/bin/. When starting my Java program with -Djava.library.path=[Directory to the attach.dll] everything works out without error output.

现在,我不想添加每个Java程序启动这个丑陋的JVM参数。因此我的问题是:

Now, I don't want to add every Java program start this ugly JVM parameter. Therefore my questions are:


  1. 我的机器配置不正确且 $ JRE / bin / 应该在库路径中吗?

如果没有,我该如何动态添加路径? System.setProperties(java.library.path,StringOfThePathToTheAttach.dll); 无效。库路径已更改,但无论如何都会出现错误。这与SecurityManager或JVM的启动有关吗?

If not, how can I add the path dynamically? System.setProperties("java.library.path",StringOfThePathToTheAttach.dll); does not work out. The library path is changed, but the error apperas anyway. Has this something to do with SecurityManager or JVM start up?


推荐答案

你的 System.setProperty(java.library.path,StringOfThePathToTheAttach.dll); 应该有效。我的猜测是你打电话太晚了。换句话说,在设置属性之前尝试访问DLL。

Your System.setProperty("java.library.path", StringOfThePathToTheAttach.dll); should work. My guess is that you're calling it too late. In other words, there is an attempt to access the DLL prior to you setting the property.

在属性为之后,是否可以输出java.library.path的当前值在代码中设置并在违规方法调用之前再次设置?

Can you output the current value for java.library.path after the property is set in code and again before the offending method call?

ie如果在看到设置属性后之前看到在attach.dll之前调用输出,则表明您的问题在哪里。

i.e. If you see "Before attach.dll call" output prior to seeing "After setting property", you know where your problem is.

编辑:

指向本机库的更好方法是使用 System.load(StringOfThePathToTheAttach.dll) - 再次,在有问题的代码行之前。

A better way to point to native libraries is to use System.load(StringOfThePathToTheAttach.dll) - again, before the offending line of code.

这篇关于Java Attach API:动态更改java.library.path的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆