2010-09-13 50 views
2

我一直在使用這個確切的Build.xml文件。我在開始使用junit任務時遇到了問題,但幾個月前我發現了這些問題。我的Ant Build文件的類路徑問題

最近,當我運行我的構建文件與測試任務時,最近我得到了所有常見的錯誤消息。

test: 
[junit] Testsuite: com.mmz.mvc.test.AgentDAOTest 
[junit] Tests run: 1, Failures: 0, Errors: 1, Time elapsed: 0 sec 
[junit] Null Test: Caused an ERROR 
[junit] com.mmz.mvc.test.AgentDAOTest 
[junit] java.lang.ClassNotFoundException: com.mmz.mvc.test.AgentDAOTest 
[junit]  at java.lang.ClassLoader.loadClass(ClassLoader.java:248) 
[junit]  at java.lang.Class.forName0(Native Method) 
[junit]  at java.lang.Class.forName(Class.java:247) 
[junit]  at org.eclipse.ant.internal.ui.antsupport.EclipseDefaultExecutor.executeTargets(EclipseDefaultExecutor.java:32) 
[junit]  at org.eclipse.ant.internal.ui.antsupport.InternalAntRunner.run(InternalAntRunner.java:423) 
[junit]  at org.eclipse.ant.internal.ui.antsupport.InternalAntRunner.main(InternalAntRunner.java:137) 

BUILD FAILED 
C:\Users\myName\Documents\Java\mmz\WEB-INF\build.xml:45: 
Testcom.mmz.mvc.test.AgentDAOTest failed 

我知道這個問題是關係到我的類路徑,但我不知道爲什麼會突然斷裂時,它已經工作了這麼久。

我的構建如下圖所示。

<property file="build.properties"/> 
<property name="src.dir" value="src"/> 
<property name="build.dir" value="classes"/> 
<property name="web.dir" value="war"/> 

<path id="build.classpath"> 
    <fileset dir="lib"> 
     <include name="*.jar"/> 
    </fileset> 
    <fileset dir="${appserver.lib}"> 
     <include name="servlet*.jar"/> 
    </fileset> 
    <pathelement path="${build.dir}"/> 
    <pathelement path="${test.dir}"/> 
</path> 

<path id="classpath.base"/> 
<path id="classpath.test"> 
<pathelement location="c:/ant/lib/junit.jar" /> 
<pathelement location="${build.dir}"/> 
<pathelement location="${src.dir}"/> 
<pathelement location="${test.dir}" /> 
<pathelement location="classes"/> 
<path refid="classpath.base" /> 
</path> 

<target name="build"> 
    <mkdir dir="${build.dir}"/> 
    <mkdir dir="${test.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="build.classpath"/> 
    </javac> 
    <javac destdir="${build.dir}" source="1.5" target="1.5" debug="true" deprecation="false" optimize="false" failonerror="true"> 
     <src path="${test.dir}"/> 
     <classpath refid="build.classpath"/> 
    </javac> 
    </target> 

    <target name="test"> 
    <junit haltonfailure="true"> 
     <classpath refid="classpath.test" /> 
     <classpath refid="build.classpath"/> 
     <formatter type="brief" usefile="false" /> 
     <test name="com.mmz.mvc.test.AgentDAOTest"/> 
     <test name="com.mmz.mvc.test.AgentProfileDAOTest"/> 
     <test name="com.mmz.mvc.test.BuyerDAOTest"/> 
     <test name="com.mmz.mvc.test.BuyerSellerDAOTest"/> 
     <test name="com.mmz.mvc.test.BaseDAOTest"/> 
     <test name="com.mmz.mvc.test.MemberDAOTest"/> 
     <test name="com.mmz.mvc.test.SellerDAOTest"/> 
    </junit> 

我不是很好的構建文件,我不理解如何設置類路徑,一切都非常好,所以如果有人可以幫助我將不勝感激。

回答

2

看起來像一個缺少的jar文件,包含類「com.mmz.mvc.test.AgentDAOTest」。讀取你的構建文件表明這個jar曾經位於你的「lib」目錄中。

我假設,當然,這個類是不在你之下「SRC」或「$ {} test.dir」目錄丟失的Java源文件.....

+0

什麼是真奇怪,我是否已經進入並在測試任務內切換了已聲明的測試的順序,並且它不會給我一個問題?你看到構建文件存在任何明顯的問題。 – TheJediCowboy 2010-09-13 23:19:28

+0

@CitadelCSAlum:如果是這樣,AgentDAOTest是否對其他Test類有依賴關係?不應該 - 但只是檢查。 – JoseK 2010-09-14 05:52:37