jmockit,openJDK和UnsatisfiedLinkError

时间:2012-03-05 11:01:26

标签: java freebsd openjdk jmockit

当尝试在OpenJDK 6上使用JMockit运行测试时,我遇到错误:

[junit] Exception in thread "main" java.lang.ExceptionInInitializerError
[junit]     at org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.run(JUnitTestRunner.java:353)
[junit]     at org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.launch(JUnitTestRunner.java:1052)
[junit]     at org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.main(JUnitTestRunner.java:906)
[junit] Caused by: java.lang.IllegalStateException: Native library for Attach API not available in this JRE
[junit]     at mockit.internal.startup.JDK6AgentLoader.getVirtualMachineImplementationFromEmbeddedOnes(JDK6AgentLoader.java:81)
[junit]     at mockit.internal.startup.JDK6AgentLoader.loadAgent(JDK6AgentLoader.java:54)
[junit]     at mockit.internal.startup.AgentInitialization.initializeAccordingToJDKVersion(AgentInitialization.java:21)
[junit]     at mockit.internal.startup.Startup.initializeIfNeeded(Startup.java:200)
[junit]     at mockit.internal.startup.Startup.initializeIfPossible(Startup.java:215)
[junit]     at junit.framework.TestResult.<clinit>(TestResult.java:19)
[junit]     ... 3 more
[junit] Caused by: java.lang.UnsatisfiedLinkError: sun.tools.attach.LinuxVirtualMachine.isLinuxThreads()Z
[junit]     at sun.tools.attach.LinuxVirtualMachine.isLinuxThreads(Native Method)
[junit]     at sun.tools.attach.LinuxVirtualMachine.<clinit>(LinuxVirtualMachine.java:364)
[junit]     at mockit.internal.startup.JDK6AgentLoader.getVirtualMachineImplementationFromEmbeddedOnes(JDK6AgentLoader.java:71)
[junit]     ... 8 more

我查看了文件夹/ usr / local / openjdk6 / jre / lib / amd64 /并找到 libattach.so 那里

但是,添加 -Djava.library.path = / usr / local / openjdk6 / jre / lib / amd64 并没有解决问题。我还能尝试什么?

2 个答案:

答案 0 :(得分:4)

尝试在 jmockit.jar之前将<jdk6home>/lib/tools.jar添加到类路径。如果这不能解决问题,那么将-javaagent:jmockit.jar作为JVM初始化参数传递肯定应该。

答案 1 :(得分:1)

在我的情况下,我注意到我指向JRE6而不是JDK 6.只要我将JAVA_HOME指向jdk 6就解决了问题