gpt4 book ai didi

java - 在 ant 中设置 javaagent

转载 作者:搜寻专家 更新时间:2023-10-31 08:04:16 25 4
gpt4 key购买 nike

我正在尝试从 Ant 脚本运行 JUnit 测试。测试使用 JMockit 模拟框架,对于 Java 5,需要将其指定为 javaagent 才能正确运行。这是我正在运行的脚本:

<!DOCTYPE project>
<project name="junit_test">
<property name="PROJECT_PATH" value="{Path to my eclipse project}" />
<property name="LIB_PATH" value="${PROJECT_PATH}/WebContent/WEB-INF/lib" />
<property name="TEST_PATH" value="WebContent/WEB-INF/classes" />

<target name="run_junit">
<junit fork="yes" forkmode="once" printsummary="true">
<jvmarg value="-javaagent:${LIB_PATH}/jmockit.jar" />

<classpath path="${LIB_PATH}/jmockit.jar" />
<classpath path="${LIB_PATH}/junit-4.8.2.jar" />

<batchtest>
<fileset dir="${TEST_PATH}">
<include name="**/*Test.class"/>
</fileset>
</batchtest>
</junit>

<junitreport todir="/junitOut">
<fileset dir="/junitOut">
<include name="INCOMPLETE-*.xml"/>
<include name="TEST-*.xml"/>
</fileset>
<report todir="/junitOut/html"/>
</junitreport>
</target>
</project>

我感觉我没有正确设置 javaagent。此异常的测试错误:

java.lang.reflect.InvocationTargetException
at java.lang.reflect.Constructor.newInstance(Constructor.java:515)
at org.eclipse.ant.internal.ui.antsupport.EclipseDefaultExecutor.executeTargets(EclipseDefaultExecutor.java:32)
at org.eclipse.ant.internal.ui.antsupport.InternalAntRunner.run(InternalAntRunner.java:423)
at org.eclipse.ant.internal.ui.antsupport.InternalAntRunner.main(InternalAntRunner.java:137)
at java.lang.J9VMInternals.initialize(J9VMInternals.java:140)
at java.lang.J9VMInternals.initialize(J9VMInternals.java:140)
at java.lang.J9VMInternals.initialize(J9VMInternals.java:167)
Caused by: java.lang.RuntimeException: com.sun.tools.attach.AttachNotSupportedException: Unable to enqueue operation: the target VM does not support attach mechanism
at mockit.internal.startup.JDK6AgentLoader.attachToThisVM(JDK6AgentLoader.java:113)
at mockit.internal.startup.JDK6AgentLoader.loadAgent(JDK6AgentLoader.java:77)
at mockit.internal.startup.AgentInitialization.initializeAccordingToJDKVersion(AgentInitialization.java:41)
at mockit.internal.startup.Startup.initializeIfNeeded(Startup.java:203)
at java.lang.J9VMInternals.initializeImpl(Native Method)
at java.lang.J9VMInternals.initialize(J9VMInternals.java:200)
at java.lang.J9VMInternals.initialize(J9VMInternals.java:167)
at java.lang.J9VMInternals.initialize(J9VMInternals.java:167)
Caused by: com.sun.tools.attach.AttachNotSupportedException: Unable to enqueue operation: the target VM does not support attach mechanism
at sun.tools.attach.WindowsVirtualMachine.(WindowsVirtualMachine.java:58)
at sun.tools.attach.WindowsAttachProvider.attachVirtualMachine(WindowsAttachProvider.java:58)
at com.sun.tools.attach.VirtualMachine.attach(VirtualMachine.java:207)
at mockit.internal.startup.JDK6AgentLoader.attachToThisVM(JDK6AgentLoader.java:110)

我的 javaagent 设置是否正确?如果是,还有什么可能导致此错误?

最佳答案

我不知道这是否是解决方案,但您没有正确设置类路径。试试这个:

<classpath>
<pathelement location="${LIB_PATH}/jmockit.jar" />
<pathelement location="${LIB_PATH}/junit-4.8.2.jar" />
</classpath>

关于java - 在 ant 中设置 javaagent,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5353155/

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