2017-04-23 139 views
0

以下是我的Build.xml文件。我試圖通過Build.xml執行我的TestNG.xml,但每次都得到下面的錯誤。從Build.xml(ANT)執行TestNG.xml文件

[TestNG的]無法在類路徑中尋找類:

下面的文件,直到編譯目標做工精細。我想在exec target中寫入的代碼存在一些問題。

如果我嘗試單獨執行我的TestNG.xml文件,它工作得很好。沒有問題。但是當我從Build.xml執行我的TestNG.xml時,問題就出現了。

我曾嘗試了許多,我就發現計算器等方法解決這個問題:

  • 清潔項目
  • 更新TestNG的庫 但沒有成功。

有人能幫助我嗎?

<property name="lib" value="./lib" /> 

<property name="bin" value="./bin" /> 

<path id="Sample Ant build.classpath"> 
    <pathelement location="${output}" /> 
    <fileset dir="${lib}"> 
     <include name="**/*.jar" /> 
    </fileset> 
</path> 

<target name="init"> 
    <delete dir="${bin}"> 
    </delete> 
    <mkdir dir="${bin}" /> 
</target> 

<target name="compile" depends="init"> 
    <javac srcdir="${src}" 
     destdir="${bin}" 
     includeantruntime="false" 
     debug="true"> 
     <classpath refid="Sample Ant build.classpath"/> 
    </javac> 
</target> 

<!-- Runs the file and generates Reportng report for TestNG--> 
<taskdef name="testng" classname="org.testng.TestNGAntTask" classpathref="Sample Ant build.classpath" /> 

<target name="exec" depends="compile"> 
    <mkdir dir="${testng_report_dir}" /> 
    <testng outputdir="${testng_report_dir}" classpathref="Sample Ant build.classpath" useDefaultListeners="true"> 
     <xmlfileset dir="${basedir}" includes="Testng.xml" /> 
    </testng> 

</target> 

回答

0

的問題是,我在build.xml已成立的類路徑。以下是正確的類路徑。

<path id="classpath"> 
    <pathelement location="${bin}" /> 
    <fileset dir="${lib}"> 
     <include name="**/*.jar" /> 
    </fileset> 
</path> 

$ {bin}是編譯.java文件後.class文件所在的目錄。