Как заставить Eclipse загрузить все свойства из файла свойств Ant? - PullRequest
0 голосов
/ 13 ноября 2010

Я использую Eclipse 3.2.0 в Red Hat Enterprise Linux Server версии 5.2 Beta (Tikanga) и пытаюсь создать проект с использованием файла сборки 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 голосов
/ 13 ноября 2010

Простой ответ заключается в том, что этот файл не является файлом, который вы вставили сюда. Самый простой способ выяснить, что не так, вставить куда-нибудь следующее, чтобы увидеть загруженный файл:

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

Это основано на том факте, что атрибут location всегда будет возвращать абсолютный путь.

ps: используйте maven, поскольку ваш скрипт сборки похож на жизненный цикл

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...