您的位置:首页 > 编程语言 > Java开发

ant运行java程序时, 它不能加载指定properties文件, 怎么处理?

2011-07-27 17:47 218 查看

 

运行时, 目录结构如下: 

 

    .

    |-- ./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>
 

 

 

 

 

 显示结果:custumerConfigIn: null。 

 

 这是为什么? 我知道是ant脚本里写的可能有问题。 同样的代码在Eclipse中运行时显示是没问题的。 

 

实验代码见附件。 

 

阅读更多
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐