如何使Eclipse从Ant属性文件加载所有属性?

时间:2010-11-12 21:44:01

标签: eclipse ant

我在Red Hat Enterprise Linux Server 5.2 Beta(Tikanga)上使用Eclipse 3.2.0,并尝试使用Ant构建文件和属性文件创建项目。当我加载构建文件时,加载的唯一属性是$ {build.dir},$ {bin.dir}和$ {dist.dir}。属性文件中的所有其他属性都不会加载。任何人都可以帮我确定为什么其他属性不会加载?请参阅下面的代码。

build.properties:

bin.dir=bin
build.dir=build
dist.dir=dist
src.dir=src
doc.dir=doc
config.dir=config
common.lib.dir=lib
reports.dir=reports

的build.xml:

tools.lib.dir=tools/lib
tools.etc.dir=tools/etc
findbugs.home.dir=tools/findbugs
findbugs.lib.dir=tools/findbugs/lib

<?xml version="1.0" encoding="UTF-8"?>
<project basedir="." default="build" name="FalconLogParser">
    <property file="build.properties" />

    <path id="compile.classpath">
        <fileset dir="${common.lib.dir}">
            <include name="*.jar" />
        </fileset>
    </path>

    <path id="run.classpath">
        <pathelement location="${build.dir}" />
        <path refid="compile.classpath" />
    </path>

    <path id="dist.classpath">
        <fileset dir="${dist.dir}">
            <include name="*.jar" />
        </fileset>
        <path refid="compile.classpath" />
    </path>

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

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

    <!-- Create directories to place classes and JARs -->
    <target name="init" description="Create directories to place classes and JARs">
        <tstamp />
        <mkdir dir="${build.dir}" />
        <mkdir dir="${build.dir}/3rdparty" />
        <mkdir dir="${build.dir}/com" />
        <mkdir dir="${bin.dir}" />
        <mkdir dir="${bin.dir}/3rdparty" />
        <mkdir dir="${dist.dir}" />
        <mkdir dir="${dist.dir}/bin" />
        <mkdir dir="${dist.dir}/bin/3rdparty" />
        <mkdir dir="${dist.dir}/cfg" />
        <mkdir dir="${dist.dir}/config" />
        <mkdir dir="${dist.dir}/logs" />
        <mkdir dir="${dist.dir}/output" />
        <mkdir dir="${dist.dir}/scripts" />
    </target>

    <!-- Remove all build artifacts -->
    <target name="clean_build" description="Remove all build artifacts">
        <delete dir="${build.dir}" />
        <delete dir="${bin.dir}" />
        <delete dir="${dist.dir}" />
    </target>

    <!-- Remove all reports -->
    <target name="clean_reports" description="Remove all reports">
        <delete dir="${reports.dir}" />
        <mkdir dir="${reports.dir}"/>
    </target>

    <!-- Remove all build artifacts -->
    <target name="clean_docs" description="Remove all documention">
        <delete dir="${doc.dir}" />
        <mkdir dir="${doc.dir}"/>
    </target>

    <!-- Compile source code -->
    <target name="build" depends="init" description="Compile Java files">
        <copy todir="${build.dir}/3rdparty" >
            <fileset dir="${common.lib.dir}"/>
        </copy>
        <javac destdir="${build.dir}">
            <src path="${src.dir}" />
            <include name="**/*.java" />
            <exclude name="**/*Test.java" />
            <!-- So that Eclipse automatically copies changed files to build directory -->
            <classpath refid="compile.classpath" />
        </javac>
    </target>

    <!-- Run unit tests -->
    <target name="test" depends="build" description="Run unit tests">
        <junit description="AllTests" fork="yes">
            <batchtest todir=".">
                <fileset dir="${src.dir}">
                    <include name="**/*Test.java" />
                </fileset>
            </batchtest>
            <formatter type="xml" usefile="yes" />
            <formatter type="plain" usefile="yes" />
            <classpath>
                <path refid="run.classpath" />
            </classpath>
        </junit>
    </target>

    <!-- Make distribution jar files -->
    <target name="jar" depends="build" description="Make distribution jar files">
        <jar destfile="${bin.dir}/falconLogParser.jar" basedir="${build.dir}/com" />
        <copy todir="${bin.dir}/3rdparty">
        <fileset dir="${build.dir}/3rdparty" />
    </copy>
    </target>

    <!-- Make distribution files -->
    <target name="dist" depends="jar" description="Make distribution files">
        <copy todir="${dist.dir}/bin">
            <fileset dir="${bin.dir}" />
        </copy>
        <copy todir="${dist.dir}/config">
            <fileset dir="${config.dir}" />
        </copy>
    </target>

    <!-- Make Java documentation for API -->
    <target name="doc" depends="build">
        <delete dir="${doc.dir}" />
        <mkdir dir="${doc.dir}" />
        <javadoc doctitle="Falcon Log Parser" classpathref="run.classpath" destdir="${doc.dir}" private="true">
            <fileset dir="${src.dir}">
                <include name="**/*.java" />
                <exclude name="**/*Test.java" />
            </fileset>
            <link href="${java.apidoc.url}" />
        </javadoc>
    </target>

    <target name="run" depends="build">
    </target>

    <!--  Static code checking -->
    <target name="checkcode" description="Static source code code checking" depends="build">

        <fileset dir="${src.dir}" id="tocheck">
            <include name="**/*.java" />
            <exclude name="**/*Test.java" />
        </fileset>

        <mkdir dir="${reports.dir}" />

        <taskdef name="pmd" classname="net.sourceforge.pmd.ant.PMDTask" classpathref="tools.classpath" />
        <pmd rulesetfiles="basic,design,coupling,strings" targetjdk="1.6">
            <formatter type="xml" toFile="${reports.dir}/pmd_report.xml" />
            <fileset refid="tocheck" />
        </pmd>
        <xslt in="${reports.dir}/pmd_report.xml" style="${tools.etc.dir}/wz-pmd-report.xslt" out="${reports.dir}/pmd_report.html" />
        <echo message="${reports.dir}/pmd_report.xml and ${reports.dir}/pmd_report.html written out" />

        <taskdef resource="checkstyletask.properties" classpathref="tools.classpath" />
        <checkstyle config="${tools.etc.dir}/sun_checks.xml" failOnViolation="false">
            <formatter type="xml" tofile="${reports.dir}/checkstyle_report.xml" />
            <fileset refid="tocheck" />
        </checkstyle>
        <echo message="${reports.dir}/checkstyle_report.xml written out" />
        <xslt 
            in="${reports.dir}/checkstyle_report.xml" 
            out="${reports.dir}/checkstyle_report.html" 
            style="${tools.etc.dir}/checkstyle-noframes-sorted.xsl" 
        />

        <taskdef name="findbugs" classname="edu.umd.cs.findbugs.anttask.FindBugsTask" classpathref="findbugs.classpath" />
        <findbugs home="${findbugs.home.dir}" output="xml" outputFile="${reports.dir}/findbugs_report.xml">
            <auxClasspath refid="compile.classpath" />
            <sourcePath path="${src.dir}" />
            <class location="${build.dir}/com" />
        </findbugs>
        <echo message="${reports.dir}/findbugs_report.xml written out" />
        <xslt 
            in="${reports.dir}/findbugs_report.xml"
            out="${reports.dir}/findbugs_report.html"
            style="${findbugs.home.dir}/src/xsl/default.xsl"
        />

    </target>

</project>

1 个答案:

答案 0 :(得分:-1)

简单回答是该文件不是您在此处粘贴的文件。找出错误的最简单方法是将以下内容粘贴到某处以查看加载的文件:

<property name="whatswrong" location="build.properties"/>
<echo>The absulute path of property file is ${whatswrong}/>

这是基于这样一个事实,即location属性总是会返回绝对路径。

ps:使用maven,因为你的构建脚本就像生命周期