gpt4 book ai didi

java - jMockit 初始化错误 : java. lang.IllegalStateException:在 JDK 9 上运行

转载 作者:塔克拉玛干 更新时间:2023-11-01 23:02:10 41 4
gpt4 key购买 nike

jmockit cannot initialize in eclipse: java.lang.IllegalStateException: Running on JDK 9 requires -javaagent:/jmockit-1.n.jar or -Djdk.attach.allowAttachSelf

如果我添加 -Djdk.attach.allowAttachSelf VM 参数,它工作正常。

为什么我需要添加该参数? jmockit 并没有说在 JDK 9 上运行时是必需的。是的,JRE 系统库指向 JDK,是的,jmockit jar 在外部库的顺序上位于 junit 之上。

版本:JUnit 4.12、Java jdk 9.0.1、jmockit 1.37、hamcrest core 1.3

java.lang.ExceptionInInitializerError at testClass.testMethod(testClass.java:20) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.base/java.lang.reflect.Method.invoke(Method.java:564) at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50) at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12) at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47) at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17) at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57) at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290) at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71) at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288) at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58) at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268) at org.junit.runners.ParentRunner.run(ParentRunner.java:363) at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:86) at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:539) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:761) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:461) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:207) Caused by: java.lang.IllegalStateException: Running on JDK 9 requires -javaagent:/jmockit-1.n.jar or -Djdk.attach.allowAttachSelf at mockit.internal.startup.AgentLoader.attachToRunningVM(AgentLoader.java:155) at mockit.internal.startup.AgentLoader.loadAgent(AgentLoader.java:60) at mockit.internal.startup.Startup.verifyInitialization(Startup.java:137) at mockit.Invocations.(Invocations.java:26) ... 24 more

最佳答案

-Djdk.attach.allowAttachSelf vm argument, it works fine.

Why would I need to add that argument?

JDK9 中的参数用于附加到本地 VM 本身,换句话说就是自附加。

jmockit 主要使用自连接进行检测,这就是他们需要这样一个标志的地方。此外,这个 must 参数在 JDK8 或以前的版本中应被忽略。

可以在 jigsaw mailing list. 上找到对此的初步讨论。


byte-buddy#295 上提出了类似的讨论和解决方法通过 @Rafael :-

ByteBuddyAgent.install() does now detect Java 9 VMs where self-attachment is forbidden and creates a helper process to attach from there.

关于java - jMockit 初始化错误 : java. lang.IllegalStateException:在 JDK 9 上运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47522449/

41 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com