2

我正在尝试使用 ant 脚本运行 JMcokit 测试。但我遇到了例外。如其他帖子中所述,我尝试使用'jvmargs'包含java代理,还尝试在类路径中的junit jar之前添加jmockit jar,但它没有用。如果我在我的 Eclipse 中添加 java 代理参数,那么我可以通过 Eclipse 运行它们,但不能通过 ant 脚本。我能够通过 ant 脚本运行它们的唯一方法是在我的 java 路径中添加 attach.dll。但这不是一个可行的解决方案,需要解决。

蚂蚁脚本:

    <!-- Run the TestSuite -->
            <junit fork="yes" description="Runs the Junit testcase." printsummary="yes"
                haltonfailure="${halt.on.junit.failure}" showoutput="yes">

                 <sysproperty key="java.library.path" path="C:/Program Files/Java/jdk1.6.0_12/jre/bin/attach.dll"/>  

                <jvmarg value="-javaagent:${lib.dir}/jmockit.jar" />

                <jvmarg value=" -Dcom.sun.management.jmxremote"/>


            <!--    <classpath path="${lib.dir}/jmockit-0.999.8.jar" />
                <classpath path="${lib.dir}/junit-4.7.jar" />-->


                <classpath>
                    <pathelement location="${lib.dir}/jmockit-0.999.8.jar" />
                    <pathelement location="${lib.dir}/junit-4.7.jar" />
                    <pathelement location="${lib.dir}/activemq-all-5.5.1.jar" />
                    <pathelement location="${classes.dir}" />
                    <!--<fileset dir="${lib.dir}">
                        <include name="**/*.jar" />
                        <exclude name="**/jmockit-0.999.8.jar, **/junit-4.7.jar" />
                    </fileset>-->
                </classpath>


                <!-- <test name="com.quest.shareplex.hadoopconnector.junits.AllTests" 
                    fork="no" todir="${junit.output.dir}"> <formatter type="xml" /> </test> -->

                <batchtest fork="no" todir="${junit.output.dir}">
                    <formatter type="xml" />
                    <fileset dir="${connector.src}">
                        <include name="**/*Test.java" />
                        <exclude name="**/*HDFSUtilsTest*.java" />
                    </fileset>
                </batchtest>

            </junit>

请让我知道,如果有任何其他方法可以工作,或者我做错了什么。我已经尝试了堆栈溢出中提到的所有方法:-尝试更改 java lib 路径-尝试更改 java 类路径-添加 java 代理但没有任何效果。

例外:

<error type="java.lang.reflect.InvocationTargetException">java.lang.reflect.InvocationTargetException
    at java.lang.reflect.Constructor.newInstance(Unknown Source)
    at org.eclipse.ant.internal.launching.remote.EclipseSingleCheckExecutor.executeTargets(EclipseSingleCheckExecutor.java:30)
    at org.eclipse.ant.internal.launching.remote.EclipseSingleCheckExecutor.executeTargets(EclipseSingleCheckExecutor.java:30)
    at org.eclipse.ant.internal.launching.remote.EclipseDefaultExecutor.executeTargets(EclipseDefaultExecutor.java:32)
    at org.eclipse.ant.internal.launching.remote.InternalAntRunner.run(InternalAntRunner.java:424)
    at org.eclipse.ant.internal.launching.remote.InternalAntRunner.main(InternalAntRunner.java:138)
</error>
  <system-out><![CDATA[]]></system-out>
  <system-err><![CDATA[java.lang.UnsatisfiedLinkError: no attach in java.library.path
java.lang.IllegalStateException: Unable to load Java agent; please add lib/tools.jar from your JDK to the classpath
    at mockit.internal.startup.JDK6AgentLoader.getVirtualMachineImplementationFromEmbeddedOnes(JDK6AgentLoader.java:82)
    at mockit.internal.startup.JDK6AgentLoader.loadAgent(JDK6AgentLoader.java:54)
    at mockit.internal.startup.AgentInitialization.initializeAccordingToJDKVersion(AgentInitialization.java:21)
    at mockit.internal.startup.Startup.initializeIfNeeded(Startup.java:203)
    at org.junit.runner.Runner.<clinit>(Runner.java:25)
    at org.junit.internal.builders.JUnit4Builder.runnerForClass(JUnit4Builder.java:13)
    at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:57)
    at org.junit.internal.builders.AllDefaultPossibilitiesBuilder.runnerForClass(AllDefaultPossibilitiesBuilder.java:29)
    at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:57)
    at org.junit.internal.requests.ClassRequest.getRunner(ClassRequest.java:24)
    at junit.framework.JUnit4TestAdapter.<init>(JUnit4TestAdapter.java:31)
    at junit.framework.JUnit4TestAdapter.<init>(JUnit4TestAdapter.java:24)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
    at java.lang.reflect.Constructor.newInstance(Unknown Source)
    at org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.run(JUnitTestRunner.java:473)
    at org.apache.tools.ant.taskdefs.optional.junit.JUnitTask.executeInVM(JUnitTask.java:1420)
    at org.apache.tools.ant.taskdefs.optional.junit.JUnitTask.execute(JUnitTask.java:848)
    at org.apache.tools.ant.taskdefs.optional.junit.JUnitTask.executeOrQueue(JUnitTask.java:1899)
    at org.apache.tools.ant.taskdefs.optional.junit.JUnitTask.execute(JUnitTask.java:800)
    at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:291)
    at sun.reflect.GeneratedMethodAccessor4.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
    at org.apache.tools.ant.Task.perform(Task.java:348)
    at org.apache.tools.ant.Target.execute(Target.java:390)
    at org.apache.tools.ant.Target.performTasks(Target.java:411)
    at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1399)
    at org.apache.tools.ant.helper.SingleCheckExecutor.executeTargets(SingleCheckExecutor.java:38)
    at org.eclipse.ant.internal.launching.remote.EclipseSingleCheckExecutor.executeTargets(EclipseSingleCheckExecutor.java:30)
    at org.apache.tools.ant.Project.executeTargets(Project.java:1251)
    at org.apache.tools.ant.taskdefs.Ant.execute(Ant.java:442)
    at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:291)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
    at org.apache.tools.ant.Task.perform(Task.java:348)
    at org.apache.tools.ant.Target.execute(Target.java:390)
    at org.apache.tools.ant.Target.performTasks(Target.java:411)
    at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1399)
    at org.apache.tools.ant.helper.SingleCheckExecutor.executeTargets(SingleCheckExecutor.java:38)
    at org.eclipse.ant.internal.launching.remote.EclipseSingleCheckExecutor.executeTargets(EclipseSingleCheckExecutor.java:30)
    at org.apache.tools.ant.Project.executeTargets(Project.java:1251)
    at org.apache.tools.ant.taskdefs.Ant.execute(Ant.java:442)
    at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:291)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
    at org.apache.tools.ant.Task.perform(Task.java:348)
    at org.apache.tools.ant.Target.execute(Target.java:390)
    at org.apache.tools.ant.Target.performTasks(Target.java:411)
    at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1399)
    at org.apache.tools.ant.Project.executeTarget(Project.java:1368)
    at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)
    at org.eclipse.ant.internal.launching.remote.EclipseDefaultExecutor.executeTargets(EclipseDefaultExecutor.java:32)
    at org.apache.tools.ant.Project.executeTargets(Project.java:1251)
    at org.eclipse.ant.internal.launching.remote.InternalAntRunner.run(InternalAntRunner.java:424)
    at org.eclipse.ant.internal.launching.remote.InternalAntRunner.main(InternalAntRunner.java:138)

谢谢,马扬克

4

2 回答 2

2

如果您在 Mac 上,这是因为分叉的 JVM 在类路径中没有 tools.jar。我今天遇到了这个并写了博客

于 2013-11-16T19:27:03.333 回答
2

看起来你的java是普通的jre。

java.library.path java.lang.IllegalStateException:无法加载 Java 代理;请将您的 JDK 中的 lib/tools.jar 添加到 mockit.internal.startup.JDK6AgentLoader.loadAgent(JDK6AgentLoader.java:54 的 mockit.internal.startup.JDK6AgentLoader.getVirtualMachineImplementationFromEmbeddedOnes(JDK6AgentLoader.java:82) 的类路径中

Jmockit 需要JDK才能工作。

于 2013-05-31T12:38:46.483 回答