2012-03-27 107 views
0

問題,我越來越麻煩想在我的junit螞蟻使用Junit的類路徑中的螞蟻:與dirset

<dirsets> 

。 這是類路徑的片段。

<target name="myTests" >  
    <junit haltonerror="true" haltonfailure="true" fork="true"> 
     <classpath> 
      <dirset dir="/my/absolute/root/path/where/I/keep/compiled/classes"> 
       <include name="com/mycompany/mytests"/> 
       </dirset> 
       <pathelement location="my/path/to/jars/myjar1.jar" /> 
       <pathelement location="my/path/to/jars/myjar2.jar" /> 
       <!-- and so on --> 
      </classpath> 
    <test name="com.mycompany.mytests.MyFirstTest" 
       outfile="${dir.report.test}/report_MyFirstTest"> 
       <formatter type="xml" /> 
</test> 
    </junit> 
    </target> 

當我啓動測試,在已經成功編譯所有的代碼,螞蟻抱怨:

java.lang.ClassNotFoundException: com.mycompany.mytests.MyFirstTest 
at java.net.URLClassLoader$1.run(URLClassLoader.java:202) 
at java.security.AccessController.doPrivileged(Native Method) 
at java.net.URLClassLoader.findClass(URLClassLoader.java:190) 
at java.lang.ClassLoader.loadClass(ClassLoader.java:306) 
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301) 
at java.lang.ClassLoader.loadClass(ClassLoader.java:247) 
at java.lang.Class.forName0(Native Method) 
at java.lang.Class.forName(Class.java:169) 

我試圖與絕對,相對路徑,它永遠不會奏效。我的類路徑包含許多指定了許多的,並且永遠不會被識別的罐子。 我的錯在哪裏?

感謝

回答

1

當我用螞蟻我用嵌套<classpath>元素,並與path-like結構中指定的類路徑前我多次 - 像這樣:

<path id="project.test.classpath"> 
    <pathelement location="/my/absolute/root/path/where/I/keep/compiled/classes" /> 
    <fileset dir="/my/path/to/jars"> 
     <include name="**/*.jar" /> 
    </fileset> 
</path> 


<target name="myTests"> 
    <junit haltonerror="true" haltonfailure="true" fork="true"> 
     <classpath refid="project.test.classpath" /> 
     <test name="com.mycompany.mytests.MyFirstTest" outfile="${dir.report.test}/report_MyFirstTest"> 
      <formatter type="xml" /> 
     </test> 
    </junit> 
</target> 

也許這適合的也是你。