2
結構中運行Java是:屬性文件不是通過示例項目的螞蟻
.
|-- ./build
| `-- ./build/TestAntLoadFile.class
|-- ./build.xml
|-- ./dist
| |-- ./dist/icpFinder.jar
| `-- ./dist/icp-finder.properties
|-- ./icp-finder_bak.properties
`-- ./src
`-- ./src/TestAntLoadFile.java
和獲取屬性文件中的代碼是:
public class TestAntLoadFile {
private static final String CUSTOMER_CONFIG_FILE_NAME
= "icp-finder.properties";
public static void main(String[] args) {
InputStream custumerConfigIn = TestAntLoadFile.class.
getClassLoader().getResourceAsStream(CUSTOMER_CONFIG_FILE_NAME);
System.out.println("custumerConfigIn: " + custumerConfigIn);
}
}
和build.xml文件核心抗衡是:
<path id="run.classpath">
<fileset dir = "${dist.dir}" >
<include name="**/*.jar"/>
<include name="**/*.properties"/>
<include name="./icp-finder.properties"/>
</fileset>
</path>
<target name="run" depends="jar">
<java fork="true" classname="TestAntLoadFile">
<classpath>
<path refid="run.classpath"/>
</classpath>
</java>
</target>
該項目在日食中運行良好,有沒有人有任何建議?
我刪除了「./」,照你說的,和該設置是:。但它再次失敗。 –
rmn190
@ mn190 - 道歉,我已經更新了我的答案。我不知何故忽略了你正在構建一個類路徑而不僅僅是一個文件集的事實。您不要將屬性文件本身包含在類路徑中,而是包含包含jar和/或目錄。 –
非常感謝!它完美的工作。 – rmn190