jmockit: Native library for Attach API not available in this JRE error

前端 未结 7 1827
时光取名叫无心
时光取名叫无心 2020-12-30 00:32

I was trying to use jmockit to unit test my project and got the following error:

java.lang.UnsatisfiedLinkError: no attach in java.library.path
java.lang.Ill         


        
相关标签:
7条回答
  • 2020-12-30 01:09

    Dao Lam, Here are some other things to try:

    • Make sure your project is using either:
      • The workspace default (That assumes that the default is your the jdk installation you just added. From the window where you added it, make sure it is checked.),
      • The jdk version, or
      • An execution Environment that uses the jdk version.
    • Pull up your system's environment variables, and add this path to it: (jdk_dir)/jre/bin. (Remember, you'll have to restart Eclipse once you've saved that to get it to take).
    • Close eclipse, and modify the shortcut you are using to start it to use (jdk_dir)/jre/bin.

    I've found that any one of these measures will allow Eclipse to find the attach.dll.

    0 讨论(0)
  • 2020-12-30 01:13

    Add the path to attach.dll to your PATH environment variable

    0 讨论(0)
  • 2020-12-30 01:15

    Go to Java Build Path of your project and change the JRE System Library and make it points to the jdk instead of jre.

    0 讨论(0)
  • 2020-12-30 01:15

    You have to set agent. You can set VM arguments if you are using eclipse and Args will be like this:

    -javaagent:local path to your jmockit jar\jmockit.jar

    eg: -javaagent:D:\jmockit.jar

    0 讨论(0)
  • 2020-12-30 01:19

    It's not tools.jar that you need, but the native library file for the "Attach API": attach.dll (or the Linux/Mac equivalent, attach.so or similar). A plain JRE does not contain this library. Instead, point Eclipse to a JDK installation, which should contain the jre/bin/attach.dll file.

    0 讨论(0)
  • 2020-12-30 01:21

    I found this issue with JDK 1.8.45 and 1.8.80 on 64-bit Windows. My solution was to copy attach.dll from the JDK's ./jre/bin directory to the ./bin. This eliminated the need for updating Eclipse and a Cygwin command line with a non-standard JAVA_HOME.

    Maybe the Windows version may be ignoring the contents of the JRE directory?

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