I’m new to Ant and wrote up a simple build.xml with some help yesterday. However after looking at the output from running ant -verbose it appears as if a class I have to handle many JUnit tests isn’t being called appropriately.
<project name="JUnit_tests" default="run" basedir=".">
<!-- Define variable properties -->
<property name="src" value="${basedir}"/>
<property name="junit" value="org.junit.runner.JUnitCore"/>
<!--<property name="junit" value="org.junit.runner.JUnitCore"/>-->
<!-- Appends all jars in the current directory to the classpath -->
<path id="compile.classpath">
<fileset dir="./">
<include name="*.jar"/>
</fileset>
</path>
<!-- Compiles all code in the current directory and append to the classpath -->
<target name="compile">
<javac destdir="${src}" srcdir="${src}">
<classpath refid="compile.classpath"/>
</javac>
</target>
<!-- Runs the Test code with junit argument as long as compile was run previously -->
<target name="run" depends="compile">
<java classname="Tests" fork="true">
<arg value="${junit}"/>
</java>
</target>
My JUnit tests are in the Tests class, and I need to run the class with
java org.junit.runner.JUnitCore Tests
However based on the following output I believe it’s being called as
java Tests org.junit.runner.JUnitCore
Ant -verbose output:
run:
[java] Executing '/usr/lib/jvm/java-6-sun-1.6.0.26/jre/bin/java' with arguments:
[java] 'Tests'
[java] 'org.junit.runner.JUnitCore'
[java]
[java] The ' characters around the executable and arguments are
[java] not part of the command.
[java] Exception in thread "main" java.lang.NoSuchMethodError: main
[java] Java Result: 1
Any ideas? I’ve been doing research but couldn’t find much about the order of arguments, specifically with a java call. Thanks!
You have interverted your argument (which is
Tests) and the main class which isorg.junit.runner.JUnitCore.<arg>are the arguments of the program<jvmarg>are the arguments of the JVMIn between the two of them, you will have the main class.
Java usage:
In your case, you want to execute the main method of
org.junit.runner.JUnitCoreand the arguments passed to that main method should beTests