簡體   English   中英

Ant-TestNG類路徑問題:getResource找不到文件

[英]Ant-TestNG classpath issue: getResource can't find the file

我有一個TestNG測試,單獨運行就可以很好地工作。 在它的某個地方,我得到了:

URL fileName = this.getClass().getClassLoader().getResource("config.properties");

我正在嘗試使用Ant運行相同的測試:

<testng outputDir="${resultsFolder}" haltOnFailure="false">
  <classpath>
      <fileset dir="./src/">
        <include name="**/*.properties"/>
      </fileset>
            -----------------------------...--------------------
 </classpath>
 <classfileset dir="correct path here" includes="**/*.class" />
</testng>

我可以在調試模式下看到config.properties在類路徑中。 但是頂部的行找不到它,它為null。

編輯:我解決了。關鍵行實際上並不直接在類路徑中搜索文件,而是在文件/文件夾中搜索。 因此,這解決了我的問題:

<pathelement location="src/"/>

謝謝您的幫助。

嘗試以此替換您的<classpath>...</classpath>

<classpath>
     <pathelement path="./src"/>
</classpath>

為了讓JVM找到config.properties的父目錄config.properties應該在類路徑中。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM