私はTestNGテストを受けています。どこかで私が得た:Ant-TestNGクラスパスの問題:getResourceがファイルを見つけることができません
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/"/>
ありがとうございました。 JVMがconfig.properties
のconfig.properties
親ディレクトリをクラスパスにする必要があります見つけるためには
<classpath>
<pathelement path="./src"/>
</classpath>
:
はsrcのサブフォルダ内のconfig.propertiesですか? – oers
いいえ、そうではありません。 srcフォルダにありましたが、この時点では別のものを試しています。ときに私は System.out.println(System.getProperties()。getProperty( "java.class.path")); config.propertiesが実際にそこにあります。 – Mooncrosser