Java – the problem of compiling JUnit test classes with ant

I'm working on JUnit with ant build There was a problem integrating XML files My test class is in the same directory as my source class When I learn how to use ant, I just want to compile all the source code and test classes

I'm using eclipse, and JUnit test classes work well when executed through eclipse This means using JUnit Jar and ant-junit-1.7 0.jar sets the classpath correctly (at least from eclipse's point of view), although I'm not sure if the latter jar is absolutely necessary

My folder structure is:

Src / code / MyClass SRC code of Java / myclasstest java

In addition, the ant file contains only one target for compiling MyClass and myclasstest. At present, I don't include any JUnit tasks, and I don't mind putting the build file in the same directory:

<target name="compile" >
  <javac srcdir="src/" />
</target>

Ant worked fine until I added myclasstest. Com to my folder Java (annotated JUnit) The output is:

[javac] C:\....\src\MyClassTest.java:3: package org.junit does not exist
cannot find symbol

My idea is that ant can't find the JUnit library Since I didn't specify the classpath, I assumed that ant would find the same location as the source file to find what it needs... How can I tell ant JUnit jar is there?

I really appreciate any idea to greet

Solution

Jars must be specified by name instead of directory use:

<javac srcdir="src/" classpath="pathtojar/junit.jar"/>

Where "path to jar" is the path containing JUnit jar

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>