Java Attach API: changing java.library.path dynamically

后端 未结 3 1666
滥情空心
滥情空心 2020-12-09 10:37

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

VirtualMachine.list()

相关标签:
3条回答
  • 2020-12-09 11:27

    Just found a link that might answer your question

    "The java.library.path is read only once when the JVM starts up. If you change this property using System.setProperty, it won't make any difference."

    http://fahdshariff.blogspot.jp/2011/08/changing-java-library-path-at-runtime.html

    0 讨论(0)
  • 2020-12-09 11:28
    System.setProperty("java.library.path", System.getProperty("java.library.path") + File.pathSeparator + FOLDER_THAT_CONTAINS_ATTACH_DLL);
    
    0 讨论(0)
  • 2020-12-09 11:42

    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.

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

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

    Edit:

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

    0 讨论(0)
提交回复
热议问题