尝试在 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 并没有解决问题。我还能尝试什么?

最佳答案

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

关于java - jmockit、openJDK 和 UnsatisfiedLinkError,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/9565497/

10-10 09:50