Running JUnit tests with Ant - java

I am trying to run my JUnit test cases, but I keep getting the error :
Test com.capscan.accentsWorld FAILED
The report is created, but the test aren't run. Here is my Ant code:
<!--this file was created by Eclipse Runnable JAR Export Wizard-->
<!--ANT 1.7 is required -->
<target name="create_run_jar">
<fail if="testsfailed" message="tests failed" />
<delete dir="outputs/reports" />
<mkdir dir="outputs/reports" />
<junit printsummary="on" errorproperty="testsfailed">
<classpath>
<pathelement location="${build.com.capscan.accentsWorld}"/>
<pathelement path="${java.class.path}"/>
</classpath>
<formatter type="plain"/>
<test name="com.capscan.accentsWorld" haltonfailure="no" outfile="result">
<formatter type="xml"/>
</test>
<batchtest fork="yes" todir="src/com/capscan/accentsWorld/" >
<fileset dir="src/com/capscan/accentsWorld/">
<include name="**/Test*.java" />
</fileset>
</batchtest>
<formatter type="xml" />
</junit>
<junitreport todir="outputs/reports">
<fileset dir="outputs/reports">
<include name="TEST-*.xml" />
</fileset>
<report todir="outputs/reports" />
</junitreport>
</target>
and here is the output message on my console:
Buildfile: C:\Documents and Settings\Ergun Polat\Desktop\Erguns Content\workspace\AccentsWorld\build.xml
create_run_jar:
[delete] Deleting directory C:\Documents and Settings\Ergun Polat\Desktop\Erguns Content\workspace\AccentsWorld\outputs\reports
[mkdir] Created dir: C:\Documents and Settings\Ergun Polat\Desktop\Erguns Content\workspace\AccentsWorld\outputs\reports
[junit] Running com.capscan.accentsWorld
[junit] Tests run: 1, Failures: 0, Errors: 1, Time elapsed: 0 sec
[junit] Test com.capscan.accentsWorld FAILED
[junitreport] Processing C:\Documents and Settings\Ergun Polat\Desktop\Erguns Content\workspace\AccentsWorld\outputs\reports\TESTS-TestSuites.xml to C:\DOCUME~1\ERGUNP~1\LOCALS~1\Temp\null1982495120
[junitreport] Loading stylesheet jar:file:/C:/ant/lib/ant-junit.jar!/org/apache/tools/ant/taskdefs/optional/junit/xsl/junit-frames.xsl
[junitreport] Transform time: 1047ms
[junitreport] Deleting: C:\DOCUME~1\ERGUNP~1\LOCALS~1\Temp\null1982495120
BUILD SUCCESSFUL
Total time: 2 seconds

I don't see any <javac> task to compile the tests. Don't you have to do that first?
And I'm not sure where you think java.class.path is coming from, but I'd set it explicitly inside your Ant build.xml
Here's a generic build.xml that I use, including the testing task. Give it a look and see if it can help you:
<?xml version="1.0" encoding="UTF-8"?>
<project name="xslt-converter" basedir="." default="package">
<property name="version" value="1.6"/>
<property name="haltonfailure" value="no"/>
<property name="out" value="out"/>
<property name="production.src" value="src"/>
<property name="production.lib" value="lib"/>
<property name="production.resources" value="config"/>
<property name="production.classes" value="${out}/production/${ant.project.name}"/>
<property name="test.src" value="test"/>
<property name="test.lib" value="lib"/>
<property name="test.resources" value="config"/>
<property name="test.classes" value="${out}/test/${ant.project.name}"/>
<property name="exploded" value="out/exploded/${ant.project.name}"/>
<property name="exploded.classes" value="${exploded}/WEB-INF/classes"/>
<property name="exploded.lib" value="${exploded}/WEB-INF/lib"/>
<property name="reports.out" value="${out}/reports"/>
<property name="junit.out" value="${reports.out}/junit"/>
<property name="testng.out" value="${reports.out}/testng"/>
<path id="production.class.path">
<pathelement location="${production.classes}"/>
<pathelement location="${production.resources}"/>
<fileset dir="${production.lib}">
<include name="**/*.jar"/>
<exclude name="**/junit*.jar"/>
<exclude name="**/*test*.jar"/>
</fileset>
</path>
<path id="test.class.path">
<path refid="production.class.path"/>
<pathelement location="${test.classes}"/>
<pathelement location="${test.resources}"/>
<fileset dir="${test.lib}">
<include name="**/junit*.jar"/>
<include name="**/*test*.jar"/>
</fileset>
</path>
<path id="testng.class.path">
<fileset dir="${test.lib}">
<include name="**/testng*.jar"/>
</fileset>
</path>
<available file="${out}" property="outputExists"/>
<target name="clean" description="remove all generated artifacts" if="outputExists">
<delete dir="${out}" includeEmptyDirs="true"/>
<delete dir="${reports.out}" includeEmptyDirs="true"/>
</target>
<target name="create" description="create the output directories" unless="outputExists">
<mkdir dir="${production.classes}"/>
<mkdir dir="${test.classes}"/>
<mkdir dir="${reports.out}"/>
<mkdir dir="${junit.out}"/>
<mkdir dir="${testng.out}"/>
<mkdir dir="${exploded.classes}"/>
<mkdir dir="${exploded.lib}"/>
</target>
<target name="compile" description="compile all .java source files" depends="create">
<!-- Debug output
<property name="production.class.path" refid="production.class.path"/>
<echo message="${production.class.path}"/>
-->
<javac srcdir="src" destdir="${out}/production/${ant.project.name}" debug="on" source="${version}">
<classpath refid="production.class.path"/>
<include name="**/*.java"/>
<exclude name="**/*Test.java"/>
</javac>
<javac srcdir="${test.src}" destdir="${out}/test/${ant.project.name}" debug="on" source="${version}">
<classpath refid="test.class.path"/>
<include name="**/*Test.java"/>
</javac>
</target>
<target name="junit-test" description="run all junit tests" depends="compile">
<!-- Debug output
<property name="test.class.path" refid="test.class.path"/>
<echo message="${test.class.path}"/>
-->
<junit printsummary="yes" haltonfailure="${haltonfailure}">
<classpath refid="test.class.path"/>
<formatter type="xml"/>
<batchtest fork="yes" todir="${junit.out}">
<fileset dir="${test.src}">
<include name="**/*Test.java"/>
</fileset>
</batchtest>
</junit>
<junitreport todir="${junit.out}">
<fileset dir="${junit.out}">
<include name="TEST-*.xml"/>
</fileset>
<report todir="${junit.out}" format="frames"/>
</junitreport>
</target>
<taskdef resource="testngtasks" classpathref="testng.class.path"/>
<target name="testng-test" description="run all testng tests" depends="compile">
<!-- Debug output
<property name="test.class.path" refid="test.class.path"/>
<echo message="${test.class.path}"/>
-->
<testng classpathref="test.class.path" outputDir="${testng.out}" haltOnFailure="${haltonfailure}" verbose="2" parallel="methods" threadcount="50">
<classfileset dir="${out}/test/${ant.project.name}" includes="**/*.class"/>
</testng>
</target>
<target name="exploded" description="create exploded deployment" depends="testng-test">
<copy todir="${exploded.classes}">
<fileset dir="${production.classes}"/>
</copy>
<copy todir="${exploded.lib}">
<fileset dir="${production.lib}"/>
</copy>
</target>
<target name="package" description="create package file" depends="exploded">
<jar destfile="${out}/${ant.project.name}.jar" basedir="${production.classes}" includes="**/*.class"/>
</target>
</project>

Try to run the ant in a verbose mode (ant -v). You should see more information.
Maybe you are missing something that is really basic like the #Test annotation in your test class (it happend to me that I only had methods annotated with #Ignore), or you have an error in a classpath. Show us fragment of your test class.

Related

Java build.xml unit testing with Travis-CI

I am trying to set up unit testing with Travis-CI for my java project, and I am having some difficulties. The issue is that I would like it to run all of the unit tests I have in the src/test/ file without having to specify the test name directly. This is because I will keep adding tests, and I would not like to constantly export the build.xml file. The xml I currently have is:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- WARNING: Eclipse auto-generated file.
Any modifications will be overwritten.
To include a user specific buildfile here, simply create one in the same
directory with the processing instruction <?eclipse.ant.import?>
as the first entry and export the buildfile again. -->
<project basedir="." default="build" name="COSC 4F90">
<property environment="env"/>
<property name="junit.output.dir" value="junit"/>
<property name="debuglevel" value="source,lines,vars"/>
<property name="target" value="1.8"/>
<property name="source" value="1.8"/>
<path id="COSC 4F90.classpath">
<pathelement location="bin"/>
<pathelement location="lib/commons-math3-3.6.1.jar"/>
<pathelement location="lib/junit.jar"/>
<pathelement location="lib/org.hamcrest.core_1.3.0.v201303031735.jar"/>
</path>
<target name="init">
<mkdir dir="bin"/>
<copy includeemptydirs="false" todir="bin">
<fileset dir="src">
<exclude name="**/*.launch"/>
<exclude name="**/*.java"/>
</fileset>
</copy>
</target>
<target name="clean">
<delete dir="bin"/>
</target>
<target depends="clean" name="cleanall"/>
<target depends="build-project" name="build"/>
<target depends="init" name="build-project">
<echo message="${ant.project.name}: ${ant.file}"/>
<javac debug="true" debuglevel="${debuglevel}" destdir="bin" includeantruntime="false" source="${source}" target="${target}">
<src path="src"/>
<classpath refid="COSC 4F90.classpath"/>
</javac>
</target>
<target name="test" depends="build"><!--depends="build"-->
<junit printsummary="withOutAndErr" haltonfailure="yes">
<classpath>
<path refid="COSC 4F90.classpath" />
<!--pathelement location="${test.build.dir}"/-->
</classpath>
<formatter type="brief" usefile="false" />
<batchtest>
<fileset dir="COSC 4F90.classpath" includes="**/*Test*.java" />
</batchtest>
</junit>
</target>
</project>
The error that I receive with Travis-CI is
Cannot find symbol
[javac] import simulation.creature.NeuralNet;
[javac] ^
If anyone could help me out it would be much appreciated.
Thanks!

jar and manifest file is not created during ant build

I am new to Ant and just followed a tutorial on how to do this. My goal is to create a .jar with manifest. But during build, the .jar is not created inside the "lib" folder. There are no errors during build so I'm kinda lost.
here's what inside the build.xml:
<?xml version="1.0"?>
<project name="converter" default="main" basedir=".">
<property name="projectName" value="Converter" />
<property name="src.dir" value="src"/>
<property name="web.dir" value="war"/>
<property name="lib.dir" location="lib"/>
<property name="build.dir" value="${web.dir}/WEB-INF/classes"/>
<property name="name" value="converter"/>
<property name="main-class" value="com.ouc.mv90.conversion.CSVtoMV90Converter" />
<!-- external libraries classpath, we don't need sources and javadoc -->
<path id="classpath">
<fileset dir="${basedir}/">
<include name="${lib.dir}/*.jar" />
<exclude name="${lib.dir}/*sources.jar"/>
<exclude name="${lib.dir}/*javadoc.jar"/>
</fileset>
</path>
<path id="master-classpath">
<fileset dir="${web.dir}/WEB-INF/lib">
<include name="${lib.dir}/*.jar" />
<include name="*.jar"/>
</fileset>
<pathelement path="${build.dir}"/>
</path>
<target name="build" description="Compile source tree java files">
<mkdir dir="${build.dir}"/>
<javac destdir="${build.dir}" source="1.5" target="1.5">
<src path="${src.dir}"/>
<classpath refid="master-classpath"/>
</javac>
</target>
<target name="init">
<mkdir dir="${build.dir}" />
</target>
<target name="compile" depends="init" description="compile the source ">
<javac includeantruntime="false" srcdir="${src.dir}" destdir="${build.dir}" classpathref="classpath" />
</target>
<target name="clean" description="Clean output directories">
<delete>
<fileset dir="${build.dir}">
<include name="**/*.class"/>
</fileset>
</delete>
</target>
<path id="master-classpath">
<fileset dir="${web.dir}/WEB-INF/lib">
<include name="*.jar"/>
</fileset>
<pathelement path="${build.dir}"/>
</path>
<target name="jar" depends="compile" description="package, output to JAR">
<jar jarfile="${lib.dir}/${projectName}.jar" basedir="${build.dir}">
<manifest>
<attribute name="Main-Class" value="${main-class}" />
<attribute name="Class-Path" value="${classpath.name}" />
</manifest>
</jar>
</target>
<!-- Default, run this -->
<target name="main" depends="clean, compile, jar" />
</project>

Ant build failure due to non-loading dependent Task class

Buildfile: /.../build.xml
build:
buildtests:
tests:
BUILD FAILED
/.../build.xml:43: Problem: failed to create task or type junit
Cause: Could not load a dependent class org/apache/tools/ant/Task
It is not enough to have Ant's optional JARs
you need the JAR files that the optional tasks depend upon.
Ant's optional task dependencies are listed in the manual.
Action: Determine what extra JAR files are needed, and place them in one of:
-/Applications/eclipse/plugins/org.apache.ant_1.7.1.v20090120-1145/lib
-/Users/cjwalsh/.ant/lib
-a directory added on the command line with the -lib argument
Do not panic, this is a common problem.
The commonest cause is a missing JAR.
This is not a bug; it is a configuration problem
Total time: 512 milliseconds
... and I've checked all the recommended directories, and yet I still keep getting this build failure. The specific JAR 'ant.jar', which I've looked into, has the class 'Task', and it is in the '/Applications/eclipse/plugins/org.apache.ant_1.7.1.v20090120-1145/lib' directory. Do I need to manually add this classpath to my build.xml as well? Here is my build.xml:
<?xml version="1.0" encoding="UTF-8"?>
<project name="springapp" basedir="." default="build">
<property file="build.properties"></property>
<property name="src.dir" value="src"></property>
<property name="web.dir" value="war"></property>
<property name="build.dir" value="${web.dir}/WEB-INF/classes"></property>
<property name="name" value="springapp"></property>
<property name="test.dir" value="test"></property>
<path id="master-classpath">
<fileset dir="${web.dir}/WEB-INF/lib">
<include name="*.jar" />
</fileset>
<fileset dir="${appserver.lib}">
<include name="servlet*.jar"></include>
</fileset>
<pathelement path="${build.dir}"></pathelement>
</path>
<target name="build" description="Compile main source tree java files">
<mkdir dir="${build.dir}" />
<javac destdir="${build.dir}" source="1.5" target="1.5" debug="true" deprecation="false" optimize="false"
failonerror="true">
<src path="${src.dir}" />
<classpath refid="master-classpath" />
</javac>
</target>
<target name="buildtests" description="Compile test tree java files">
<mkdir dir="${build.dir}" />
<javac destdir="${build.dir}" source="1.5" target="1.5" debug="true"
deprecation="false" optimize="false" failonerror="true">
<src path="${test.dir}"></src>
<classpath refid="master-classpath"></classpath>
</javac>
</target>
<target name="tests" depends="build, buildtests" description="Run tests">
<junit printsummary="on" fork="false" haltonfailure="false" failureproperty="tests.failed"
showoutput="true">
<classpath refid="master-classpath"></classpath>
<formatter type="brief" usefile="false" />
<batchtest>
<fileset dir="${build.dir}">
<include name="**/*Tests.*" />
</fileset>
</batchtest>
</junit>
<fail if="tests.failed">
tests.failed=${tests.failed}
***********************************************************************
***********************************************************************
**** One or more tests failed! Check the output ... ***************
***********************************************************************
***********************************************************************
</fail>
</target>
<target name="deploy" depends="build" description="Deploy the application">
<copy todir="${deploy.path}/${name}" preservelastmodified="true">
<fileset dir="${web.dir}">
<include name="**/*.*" />
</fileset>
</copy>
</target>
<target name="deploywar" depends="build" description="Deploy application as WAR file">
<war destfile="${name}.war" webxml="${web.dir}/WEB-INF/web.xml">
<fileset dir="${web.dir}">
<include name="**/*.*"></include>
</fileset>
</war>
<copy todir="${deploy.path}" preservelastmodified="true">
<fileset dir=".">
<include name="*.war"></include>
</fileset>
</copy>
</target>
<path id="catalina-ant-classpath">
<fileset dir="${appserver.lib}">
<include name="catalina-ant.jar"></include>
</fileset>
</path>
<taskdef name="install" classname="org.apache.catalina.ant.InstallTask">
<classpath refid="catalina-ant-classpath"></classpath>
</taskdef>
<taskdef name="reload" classname="org.apache.catalina.ant.ReloadTask">
<classpath refid="catalina-ant-classpath"></classpath>
</taskdef>
<taskdef name="list" classname="org.apache.catalina.ant.ListTask">
<classpath refid="catalina-ant-classpath" />
</taskdef>
<taskdef name="start" classname="org.apache.catalina.ant.StartTask">
<classpath refid="catalina-ant-classpath"></classpath>
</taskdef>
<taskdef name="stop" classname="org.apache.catalina.ant.StopTask">
<classpath refid="catalina-ant-classpath"></classpath>
</taskdef>
<target name="install" description="Install application in Tomcat">
<install url="${tomcat.manager.url}" username="${tomcat.manager.username}"
password="${tomcat.manager.password}"
path="/${name}"
war="${name}" />
</target>
<target name="reload" description="Reload applicatio in Tomcat">
<reload url="${tomcat.manager.url}" username="${tomcat.manager.username}"
password="${tomcat.manager.password}"
path="/${name}" />
</target>
<target name="start" description="Start tomcat application">
<start url="${tomcat.manager.url}" username="${tomcat.manager.username}"
password="${tomcat.manager.password}"
path="/${name}" />
</target>
<target name="stop" description="Stop Tomcat application">
<stop url="${tomcat.manager.url}"
username="${tomcat.manager.username}"
password="${tomcat.manager.password}"
path="/${name}" />
</target>
<target name="list" description="List Tomcat applications">
<list url="${tomcat.manager.url}"
username="${tomcat.manager.username}"
password="${tomcat.manager.password}" />
</target>
</project>
Are you starting ant from within Eclipse?
Please check in the menu {Run | External Tools Configuration...} that the Classpath tab contains "Ant Home". After expanding, does it point to valid files?

What are the best resources to learn Ant? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 6 years ago.
Improve this question
I would like to learn Ant. Can anyone recommend some good learning resources about this topic? Any resource is appreciated, from online introductory tutorials to in-depth books.
Thanks for your help!
ant.apache.org. Look at the manual.
Ant Best Practices
Won't take long - Ant's not hard.
Here's a sample, fairly reusable build.xml you can start with. It's generic enough for me to reuse. The directory naming convention should be easy to follow. I use a layout that mimics the output from IntelliJ.
<?xml version="1.0" encoding="UTF-8"?>
<project name="xslt-converter" basedir="." default="package">
<property name="version" value="1.6"/>
<property name="haltonfailure" value="no"/>
<property name="out" value="out"/>
<property name="production.src" value="src"/>
<property name="production.lib" value="lib"/>
<property name="production.resources" value="config"/>
<property name="production.classes" value="${out}/production/${ant.project.name}"/>
<property name="test.src" value="test"/>
<property name="test.lib" value="lib"/>
<property name="test.resources" value="config"/>
<property name="test.classes" value="${out}/test/${ant.project.name}"/>
<property name="exploded" value="out/exploded/${ant.project.name}"/>
<property name="exploded.classes" value="${exploded}/WEB-INF/classes"/>
<property name="exploded.lib" value="${exploded}/WEB-INF/lib"/>
<property name="reports.out" value="${out}/reports"/>
<property name="junit.out" value="${reports.out}/junit"/>
<property name="testng.out" value="${reports.out}/testng"/>
<path id="production.class.path">
<pathelement location="${production.classes}"/>
<pathelement location="${production.resources}"/>
<fileset dir="${production.lib}">
<include name="**/*.jar"/>
<exclude name="**/junit*.jar"/>
<exclude name="**/*test*.jar"/>
</fileset>
</path>
<path id="test.class.path">
<path refid="production.class.path"/>
<pathelement location="${test.classes}"/>
<pathelement location="${test.resources}"/>
<fileset dir="${test.lib}">
<include name="**/junit*.jar"/>
<include name="**/*test*.jar"/>
</fileset>
</path>
<path id="testng.class.path">
<fileset dir="${test.lib}">
<include name="**/testng*.jar"/>
</fileset>
</path>
<available file="${out}" property="outputExists"/>
<target name="clean" description="remove all generated artifacts" if="outputExists">
<delete dir="${out}" includeEmptyDirs="true"/>
<delete dir="${reports.out}" includeEmptyDirs="true"/>
</target>
<target name="create" description="create the output directories" unless="outputExists">
<mkdir dir="${production.classes}"/>
<mkdir dir="${test.classes}"/>
<mkdir dir="${reports.out}"/>
<mkdir dir="${junit.out}"/>
<mkdir dir="${testng.out}"/>
<mkdir dir="${exploded.classes}"/>
<mkdir dir="${exploded.lib}"/>
</target>
<target name="compile" description="compile all .java source files" depends="create">
<!-- Debug output
<property name="production.class.path" refid="production.class.path"/>
<echo message="${production.class.path}"/>
-->
<javac srcdir="src" destdir="${out}/production/${ant.project.name}" debug="on" source="${version}">
<classpath refid="production.class.path"/>
<include name="**/*.java"/>
<exclude name="**/*Test.java"/>
</javac>
<javac srcdir="${test.src}" destdir="${out}/test/${ant.project.name}" debug="on" source="${version}">
<classpath refid="test.class.path"/>
<include name="**/*Test.java"/>
</javac>
</target>
<target name="junit-test" description="run all junit tests" depends="compile">
<!-- Debug output
<property name="test.class.path" refid="test.class.path"/>
<echo message="${test.class.path}"/>
-->
<junit printsummary="yes" haltonfailure="${haltonfailure}">
<classpath refid="test.class.path"/>
<formatter type="xml"/>
<batchtest fork="yes" todir="${junit.out}">
<fileset dir="${test.src}">
<include name="**/*Test.java"/>
</fileset>
</batchtest>
</junit>
<junitreport todir="${junit.out}">
<fileset dir="${junit.out}">
<include name="TEST-*.xml"/>
</fileset>
<report todir="${junit.out}" format="frames"/>
</junitreport>
</target>
<taskdef resource="testngtasks" classpathref="testng.class.path"/>
<target name="testng-test" description="run all testng tests" depends="compile">
<!-- Debug output
<property name="test.class.path" refid="test.class.path"/>
<echo message="${test.class.path}"/>
-->
<testng classpathref="test.class.path" outputDir="${testng.out}" haltOnFailure="${haltonfailure}" verbose="2" parallel="methods" threadcount="50">
<classfileset dir="${out}/test/${ant.project.name}" includes="**/*.class"/>
</testng>
</target>
<target name="exploded" description="create exploded deployment" depends="testng-test">
<copy todir="${exploded.classes}">
<fileset dir="${production.classes}"/>
</copy>
<copy todir="${exploded.lib}">
<fileset dir="${production.lib}"/>
</copy>
</target>
<target name="package" description="create package file" depends="exploded">
<jar destfile="${out}/${ant.project.name}.jar" basedir="${production.classes}" includes="**/*.class"/>
</target>
</project>
The apache Ant manual
Manning's Ant In Action

Yet another Ant + JUnit classpath problem

I'm developing an Eclipse SWT application using Eclipse. There are also some JUnit 4 tests, which test some DAO's. But when I try to run the tests via an ant build, all of the tests fail, because the test classes aren't found.
Google brought up about a million of people who all have the same problem, but none of their solutions seem to work for me -.- .
These are the contents of my build.xml file:
<property name="test.reports" value="./test/reports" />
<property name="classes" value="build" />
<path id="project.classpath">
<pathelement location="${classes}" />
</path>
<target name="testreport">
<mkdir dir="${test.reports}" />
<junit fork="yes" printsummary="no" haltonfailure="no">
<batchtest fork="yes" todir="${test.reports}" >
<fileset dir="${classes}">
<include name="**/Test*.class" />
</fileset>
</batchtest>
<formatter type="xml" />
<classpath refid="project.classpath" />
</junit>
<junitreport todir="${test.reports}">
<fileset dir="${test.reports}">
<include name="TEST-*.xml" />
</fileset>
<report todir="${test.reports}" />
</junitreport>
</target>
The test classes are in the build-directory together with the application classes, although they are in some subfolders according to their packages.
Maybe this is important too: At first Ant complained that JUnit wasn't in its classpath, but since I put it there (with the eclipse configuration editor) it complains about JUnit being in its classpath twice.
WARNING: multiple versions of ant detected in path for junit
[junit] jar:file:C:/Users/as df/Documents/eclipse/plugins/org.apache.ant_1.7.1.v20090120-1145/lib/ant.jar!/org/apache/tools/ant/Project.class
[junit] and jar:file:/C:/Users/as%20df/Documents/eclipse/plugins/org.apache.ant_1.7.1.v20090120-1145/lib/ant.jar!/org/apache/tools/ant/Project.class
I've tried specifying each and every subdirectory, each and every class file, I've tried filesets and filelists, nothing seems to work.
Thanks for your help, I've been sitting for hours on this thing now...
I was getting this only when using the 'fork=true' option to the junit task. It was happening because my ANT_HOME had '..' in it (e.g. '/3rdparth/jboss/jboss-5/../tools'). Once I reduced that path, the 'multiple versions of ant' warning went away.
I had the same problem 'multiple versions of ant detected in path for junit'. The problem went away when I renamed by Eclipse_Home directory and removed special characters from it. The path had '[1]' in it which was causing the problem.
This Ant build.xml works fine for me. Check out the properties to see if the directory structure matches yours; adjust as needed.
<?xml version="1.0" encoding="UTF-8"?>
<project name="xslt-converter" basedir="." default="package">
<property name="version" value="1.6"/>
<property name="haltonfailure" value="no"/>
<property name="out" value="out"/>
<property name="production.src" value="src"/>
<property name="production.lib" value="lib"/>
<property name="production.resources" value="config"/>
<property name="production.classes" value="${out}/production/${ant.project.name}"/>
<property name="test.src" value="test"/>
<property name="test.lib" value="lib"/>
<property name="test.resources" value="config"/>
<property name="test.classes" value="${out}/test/${ant.project.name}"/>
<property name="exploded" value="out/exploded/${ant.project.name}"/>
<property name="exploded.classes" value="${exploded}/WEB-INF/classes"/>
<property name="exploded.lib" value="${exploded}/WEB-INF/lib"/>
<property name="reports.out" value="${out}/reports"/>
<property name="junit.out" value="${reports.out}/junit"/>
<property name="testng.out" value="${reports.out}/testng"/>
<path id="production.class.path">
<pathelement location="${production.classes}"/>
<pathelement location="${production.resources}"/>
<fileset dir="${production.lib}">
<include name="**/*.jar"/>
<exclude name="**/junit*.jar"/>
<exclude name="**/*test*.jar"/>
</fileset>
</path>
<path id="test.class.path">
<path refid="production.class.path"/>
<pathelement location="${test.classes}"/>
<pathelement location="${test.resources}"/>
<fileset dir="${test.lib}">
<include name="**/junit*.jar"/>
<include name="**/*test*.jar"/>
</fileset>
</path>
<path id="testng.class.path">
<fileset dir="${test.lib}">
<include name="**/testng*.jar"/>
</fileset>
</path>
<available file="${out}" property="outputExists"/>
<target name="clean" description="remove all generated artifacts" if="outputExists">
<delete dir="${out}" includeEmptyDirs="true"/>
<delete dir="${reports.out}" includeEmptyDirs="true"/>
</target>
<target name="create" description="create the output directories" unless="outputExists">
<mkdir dir="${production.classes}"/>
<mkdir dir="${test.classes}"/>
<mkdir dir="${reports.out}"/>
<mkdir dir="${junit.out}"/>
<mkdir dir="${testng.out}"/>
<mkdir dir="${exploded.classes}"/>
<mkdir dir="${exploded.lib}"/>
</target>
<target name="compile" description="compile all .java source files" depends="create">
<!-- Debug output
<property name="production.class.path" refid="production.class.path"/>
<echo message="${production.class.path}"/>
-->
<javac srcdir="src" destdir="${out}/production/${ant.project.name}" debug="on" source="${version}">
<classpath refid="production.class.path"/>
<include name="**/*.java"/>
<exclude name="**/*Test.java"/>
</javac>
<javac srcdir="${test.src}" destdir="${out}/test/${ant.project.name}" debug="on" source="${version}">
<classpath refid="test.class.path"/>
<include name="**/*Test.java"/>
</javac>
</target>
<target name="junit-test" description="run all junit tests" depends="compile">
<!-- Debug output
<property name="test.class.path" refid="test.class.path"/>
<echo message="${test.class.path}"/>
-->
<junit printsummary="yes" haltonfailure="${haltonfailure}">
<classpath refid="test.class.path"/>
<formatter type="xml"/>
<batchtest fork="yes" todir="${junit.out}">
<fileset dir="${test.src}">
<include name="**/*Test.java"/>
</fileset>
</batchtest>
</junit>
<junitreport todir="${junit.out}">
<fileset dir="${junit.out}">
<include name="TEST-*.xml"/>
</fileset>
<report todir="${junit.out}" format="frames"/>
</junitreport>
</target>
<taskdef resource="testngtasks" classpathref="testng.class.path"/>
<target name="testng-test" description="run all testng tests" depends="compile">
<!-- Debug output
<property name="test.class.path" refid="test.class.path"/>
<echo message="${test.class.path}"/>
-->
<testng classpathref="test.class.path" outputDir="${testng.out}" haltOnFailure="${haltonfailure}" verbose="2" parallel="methods" threadcount="50">
<classfileset dir="${out}/test/${ant.project.name}" includes="**/*.class"/>
</testng>
</target>
<target name="exploded" description="create exploded deployment" depends="testng-test">
<copy todir="${exploded.classes}">
<fileset dir="${production.classes}"/>
</copy>
<copy todir="${exploded.lib}">
<fileset dir="${production.lib}"/>
</copy>
</target>
<target name="package" description="create package file" depends="exploded">
<jar destfile="${out}/${ant.project.name}.jar" basedir="${production.classes}" includes="**/*.class"/>
</target>
</project>

Categories