gpt4 book ai didi

java - 运行 run 目标时出现 Ant 构建错误

转载 作者:行者123 更新时间:2023-12-01 12:47:00 25 4
gpt4 key购买 nike

我正在使用 ant 1.9.0 来运行我的 Java 项目。我有一个 bat 文件,其中包含命令 ant cleancompile run。clean 和编译正在工作,但对于目标运行,我遇到以下错误

 C:\Users\Susanta\MyMaven\MyMavenProject\build] on class org.apache.
tools.ant.taskdefs.optional.junit.XMLJUnitResultFormatter: java.lang.NoClassDefFoundErrorjunit/framework/TestListener

我正在附加 build.xml,请让我知道 build.xml 中的问题

<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE project [
]>

<project name="MyMavenProject" default="usage" basedir=".">

<!-- ========== Initialize Properties =================================== -->
<property environment="env"/>

<property name="ws.home" value="${basedir}"/>
<property name="ws.jars" value="${user.home}/.m2/repository/"/>
<property name="test.dest" value="${ws.home}/build"/>
<property name="test.src" value="${ws.home}/src"/>
<property name="test.reportsDir" value="${test.dest}/test_reports"/>




<path id="testcase.path">


<pathelement location="${test.dest}"/>

<fileset dir="${ws.jars}">
<include name="*.jar"/>
</fileset>

</path>




<target name="setClassPath" unless="test.classpath">
<path id="classpath_jars">
<fileset dir="${ws.jars}" includes="**/*.jar"/>
</path>
<pathconvert pathsep=":"
property="test.classpath"
refid="classpath_jars"/>
</target>

<target name="init" depends="setClassPath">
<tstamp>
<format property="start.time" pattern="MM/dd/yyyy hh:mm aa" />
</tstamp>
<condition property="ANT"
value="${env.ANT_HOME}/bin/ant.bat"
else="${env.ANT_HOME}/bin/ant">
<os family="windows" />
</condition>

</target>

<!-- all -->
<target name="all">
</target>

<!-- clean -->
<target name="clean">
<delete dir="${test.dest}"/>
</target>

<!-- compile -->
<target name="compile" depends="init, clean" >
<delete includeemptydirs="true" quiet="true">
<fileset dir="${test.dest}" includes="**/*"/>
</delete>
<echo message="making directory..."/>
<mkdir dir="${test.dest}"/>
<echo message="classpath------: ${test.classpath}"/>
<echo message="compiling..."/>
<javac
debug="true"
destdir="${test.dest}"
srcdir="${test.src}"
target="1.5"
classpath="${test.classpath}"
>
</javac>
</target>

<!-- build -->
<target name="build" depends="init">
</target>




<target name="usage">
<echo>
ant run will execute the test
</echo>
</target>

<path id="test.run">
<fileset dir="${ws.jars}" includes="**/*.jar"/>
</path>



<target name="run" >
<delete includeemptydirs="true" quiet="true">
<fileset dir="${test.reportsDir}" includes="**/*"/>
</delete>
<java jar="${ws.jars}" fork="true" spawn="true" />
<junit fork="yes" haltonfailure="no" printsummary="yes">
<classpath refid="test.run" />

<!-- <classpath ="${test.classpath}"/> -->
<batchtest todir="${test.reportsDir}" fork="true">
<fileset dir="${test.dest}">

<!--include name="tests/LoginTest.class" />
<include name="tests/Parameterized_Test.class" />
<include name="tests/TestApplication.class" /-->
<include name="com/testing/GoogleTest.class" />
<include name="com/testing/YahooTest.class" />





</fileset>
</batchtest>
<formatter type="xml" />
<classpath refid="testcase.path" />
</junit>
<junitreport todir="${test.reportsDir}">
<fileset dir="${test.reportsDir}">
<include name="TEST-*.xml" />
</fileset>
<report todir="${test.reportsDir}" />
</junitreport>
</target>

下面是错误:

   C:\Users\Susanta\MyMaven\MyMavenProject\build] on class org.apache.
tools.ant.taskdefs.optional.junit.XMLJUnitResultFormatter: java.lang.NoClassDefF
oundError: junit/framework/TestListener
[exec] at java.lang.ClassLoader.defineClass1(Native Method)
[exec] at java.lang.ClassLoader.defineClass(ClassLoader.java:791)
[exec] at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
[exec] at java.net.URLClassLoader.defineClass(URLClassLoader.java:449)
[exec] at java.net.URLClassLoader.access$100(URLClassLoader.java:71)
[exec] at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
[exec] at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
[exec] at java.security.AccessController.doPrivileged(Native Method)
[exec] at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
[exec] at java.lang.ClassLoader.loadClass(ClassLoader.java:423)
[exec] at java.lang.ClassLoader.loadClass(ClassLoader.java:356)
[exec] at org.apache.tools.ant.AntClassLoader.findBaseClass(AntClassLoader.java:1385)
[exec] at org.apache.tools.ant.AntClassLoader.loadClass(AntClassLoaderjava:1064)
[exec] at org.apache.tools.ant.util.SplitClassLoader.loadClass(SplitClassLoader.java:58)
[exec] at java.lang.ClassLoader.loadClass(ClassLoader.java:356)
[exec] at java.lang.ClassLoader.defineClass1(Native Method)
[exec] at java.lang.ClassLoader.defineClass(ClassLoader.java:791)
[exec] at org.apache.tools.ant.AntClassLoader.defineClassFromData(AntClassLoader.java:1128)
[exec] at org.apache.tools.ant.AntClassLoader.getClassFromStream(AntClassLoader.java:1299)
[exec] at org.apache.tools.ant.AntClassLoader.findClassInComponents(AntClassLoader.java:1354)
[exec] at org.apache.tools.ant.AntClassLoader.findClass(AntClassLoaderjava:1315)
[exec] at org.apache.tools.ant.util.SplitClassLoader.loadClass(SplitClassLoader.java:52)
[exec] at java.lang.ClassLoader.loadClass(ClassLoader.java:356)
[exec] at java.lang.Class.forName0(Native Method)
[exec] at java.lang.Class.forName(Class.java:266)
[exec] at

org.apache.tools.ant.taskdefs.optional.junit.FormatterElement.createFormatter(FormatterElement.java:286)
[exec] at org.apache.tools.ant.taskdefs.optional.junit.JUnitTask.logVmExit(JUnitTask.java:1653)
[exec] at org.apache.tools.ant.taskdefs.optional.junit.JUnitTask.logVmCrash(JUnitTask.java:1617)
[exec] at org.apache.tools.ant.taskdefs.optional.junit.JUnitTask.executeAsForked(JUnitTask.java:1099)
[exec] at org.apache.tools.ant.taskdefs.optional.junit.JUnitTask.execute(JUnitTask.java:851)
[exec] at org.apache.tools.ant.taskdefs.optional.junit.JUnitTask.executeOrQueue(JUnitTask.java:1899)
[exec] at org.apache.tools.ant.taskdefs.optional.junit.JUnitTask.execute(JUnitTask.java:800)
[exec] at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:291)
[exec] at sun.reflect.GeneratedMethodAccessor4.invoke(Unknown Source)
[exec] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
[exec] at java.lang.reflect.Method.invoke(Method.java:601)
[exec] at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
[exec] at org.apache.tools.ant.Task.perform(Task.java:348)
[exec] at org.apache.tools.ant.Target.execute(Target.java:435)
[exec] at org.apache.tools.ant.Target.performTasks(Target.java:456)
[exec] at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1393)
[exec] at org.apache.tools.ant.Project.executeTarget(Project.java:1364)

[exec] at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)
[exec] at org.apache.tools.ant.Project.executeTargets(Project.java:1248)
[exec] at org.apache.tools.ant.Main.runBuild(Main.java:851)
[exec] at org.apache.tools.ant.Main.startAnt(Main.java:235)
[exec] at org.apache.tools.ant.launch.Launcher.run(Launcher.java:280)
[exec] at org.apache.tools.ant.launch.Launcher.main(Launcher.java:109)
[exec] Caused by: java.lang.ClassNotFoundException: junit.framework.TestListener
[exec] at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
[exec] at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
[exec] at java.security.AccessController.doPrivileged(Native Method)
[exec] at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
[exec] at java.lang.ClassLoader.loadClass(ClassLoader.java:423)
[exec] at java.lang.ClassLoader.loadClass(ClassLoader.java:356)
[exec] ... 48 more
[exec]
[exec] Total time: 7 seconds
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 10.773s
[INFO] Finished at: Mon Jul 07 03:01:39 IST 2014
[INFO] Final Memory: 7M/18M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-antrun-plugin:1.7:
run (default) on project MyMavenProject: An Ant BuildException has occured: exec
returned: 1
[ERROR] around Ant part ...<exec dir="C:\Users\Susanta\MyMaven\MyMavenProject" e
xecutable="C:\Users\Susanta\MyMaven\MyMavenProject\testrunner.bat" failonerror="
true">... @ 5:142 in C:\Users\Susanta\MyMaven\MyMavenProject\target\antrun\build
-runtheapp.xml
[ERROR] -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal o
rg.apache.maven.plugins:maven-antrun-plugin:1.7:run (default) on project MyMaven
Project: An Ant BuildException has occured: exec returned: 1
around Ant part ...<exec dir="C:\Users\Susanta\MyMaven\MyMavenProject" executabl
e="C:\Users\Susanta\MyMaven\MyMavenProject\testrunner.bat" failonerror="true">..
. @ 5:142 in C:\Users\Susanta\MyMaven\MyMavenProject\target\antrun\build-runthea
pp.xml
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:216)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:84)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:59)
at org.apache.maven.lifecycle.internal.LifecycleStarter.singleThreadedBuild(LifecycleStarter.java:183)
at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:161)
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:317)
at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:152)
at org.apache.maven.cli.MavenCli.execute(MavenCli.java:555)
at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:214)
at org.apache.maven.cli.MavenCli.main(MavenCli.java:158)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:289)
at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229)
at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:415)
at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:356)
Caused by: org.apache.maven.plugin.MojoExecutionException: An Ant BuildException
has occured: exec returned: 1
around Ant part ...<exec dir="C:\Users\Susanta\MyMaven\MyMavenProject" executable="C:\Users\Susanta\MyMaven\MyMavenProject\testrunner.bat" failonerror="true">..
. @ 5:142 in C:\Users\Susanta\MyMaven\MyMavenProject\target\antrun\build-runtheapp.xml

最佳答案

这似乎是 ANT 1.9.0 中的一个已知错误。参见这里:Bamboo Ant Task fails when running junit task

阅读评论 #4、#5、#8 和 #20 @ THIS Link寻求一些帮助。

关于java - 运行 run 目标时出现 Ant 构建错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24600857/

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