Ant:路径在构建过程中无缘无故地被修改

时间:2016-06-17 11:18:53

标签: ant

我有一个Ant脚本,负责编译和构建一组位于不同目录中的项目。在过去,所有这些项目都在同一条道路上,所以我没有路径问题,提到相同的路径,它没关系。但是,现在我有一个不同的文件夹结构,我的Ant脚本自然会出错,我试图解决。

我曾经有以下文件夹结构:

-mainRepository
 --Project1
   ---subProject1
   ---subProject2
   ---subProject3
   ---subProject6
   ---subProject7
   ---subProject7
   --- ...

以下是我现在使用的文件夹结构:

-mainRepository
 --Project1
   ---subProject1
   ---subProject2
   ---subProject3
   --- ...
 --Project2
   ---subProject1
   ---subProject2
   ---subProject3
   --- ...

非常简单。现在,我的Ant脚本无法继续构建它所在的行:

<copy todir="${component.release.dir}/bundle">
    <fileset dir="${base.dir}/bundle" includes="**" />
</copy>

其中${base.dir}在上面定义为

<property name="base.dir" location="../subProject1" />

当我运行脚本时,出现以下错误:

/home/name/mainRepository/Project1/Project1/subProject1/bundle does not exist.

请注意Project1重复两次,情况并非如此。奇怪的是,当我将鼠标悬停在属性${base.dir}上时,会出现一个小对话框,路径绝对正确,显示为:

/home/name/mainRepository/Project1/subProject1/bundle 

然而在执行期间,不知何故另一个Project1进入此路径,因此它失败了。我想引入另一个属性并将其称为${alternative.dir},并将其指向我想要的路径。结果仍然相同。再次出错。我试着玩路径,来回一个目录,没有运气。如果重要,我正在使用Eclipse环境。

此时使用Ant非常令人沮丧,因为我不知道为什么它会不断添加内容。

有什么想法吗?

更新<!/强>

好吧,我想我必须把我的蚂蚁文件放在这里,就在那里:

deploy.ant

<?xml version="1.0" encoding="UTF-8"?>
<project basedir="." default="forbidden" name="subProject.mw.deploy">

    <!-- DO NOT RUN THIS FILE WITHOUT PARAMETERS 
        This file builds a release
    -->

    <!-- ************************************************************** -->
    <!-- ************************** properties ************************ -->
    <!-- ************************************************************** -->

    <property name="subProject.dir" location="../subProject/subProject.mw" />
    <property name="base.dir" location="../subProject.mw" />

    <!-- ************************************************************** -->
    <!-- ************************** ant libraries ********************* -->
    <!-- ************************************************************** -->

    <!-- this library requires the subProject.mw project parallel to this project -->
    <taskdef resource="net/sf/antcontrib/antcontrib.properties">
        <classpath>
            <pathelement location="${subProject.dir}/tools/ant/ant-contrib.jar" />
        </classpath>
    </taskdef>

    <!-- ************************************************************** -->
    <!-- ************************** targets *************************** -->
    <!-- ************************************************************** -->


    <target name="clean">
        <delete dir="${install.dir}" />
    </target>

    <target name="prepare">
        <mkdir dir="${install.dir}" />
        <copy file="${template.dir}/run.all.ant" todir="${install.dir}" />
        <copy file="${template.dir}/run.all.sh" todir="${install.dir}" />
        <copy file="${template.dir}/kill.all.sh" todir="${install.dir}" />
        <copy file="${template.dir}/packLogs.sh" todir="${install.dir}" />
    </target>

    <target name="build-subProject">
        <ant inheritall="false" dir="${subProject.dir}" antfile="build.all.xml" target="all" />
    </target>

    <!-- ************************** bundle projects *************************** -->

    <target name="build-bundles">
        <echo message="Building bundles" />
        <foreach target="build-bundle-project" param="bundle.project.dir">
            <path refid="bundle.projects" />
        </foreach>
    </target>

    <target name="build-bundle-project">
        <basename file="${bundle.project.dir}" property="bundle.project.name" />
        <echo message="Building bundle project: ${bundle.project.dir}" />
        <ant dir="${bundle.project.dir}" antfile="build.xml" />
    </target>

    <target name="deploy-bundles">
        <property name="test" refid="component.projects" />
        <echo message=" ---- Component Projects: ${test}" />
        <property name="test2" refid="bundle.projects" />
        <echo message=" ---- Bundle Projects: ${test2}" />

        <foreach target="deploy-bundle-project" inheritrefs="true" inheritall="true" param="bundle.project.dir">
            <path refid="bundle.projects" />
            <param name="component.release.dir" value="${component.release.dir}" />
        </foreach>
    </target>

    <target name="deploy-bundle-project">
        <echo>Deploying bundles from ${bundle.project.dir} to ${component.release.dir}</echo>
        <copy todir="${component.release.dir}/bundle/component">
            <fileset dir="${bundle.project.dir}/build">
                <include name="**.jar" />
            </fileset>
        </copy>
    </target>

    <!-- ************************** message projects *************************** -->

    <target name="build-messages">
        <foreach target="build-message-project" param="message.project.dir">
            <path refid="message.projects" />
        </foreach>
    </target>

    <target name="build-message-project">
        <basename file="${message.project.dir}" property="message.project.name" />
        <echo message="Building message project: ${message.project.dir}" />
        <if>
            <available file="${message.project.dir}/build.xml" />
            <then>
                <ant dir="${message.project.dir}" antfile="build.xml" />
            </then>
            <else>
                <echo message="Skipping message project du to missing build.xml in: ${message.project.dir} " />
            </else>
        </if>
    </target>

    <target name="deploy-messages">
        <property name="test" refid="component.projects" />
        <echo message=" ---- Component Projects: ${test}" />
        <property name="test2" refid="message.projects" />
        <echo message=" ---- Message Projects: ${test2}" />

        <foreach target="deploy-message-project" inheritrefs="true" inheritall="true" param="message.project.dir">
            <path refid="message.projects" />
            <param name="component.release.dir" value="${component.release.dir}" />
        </foreach>
    </target>

    <target name="deploy-message-project">
        <echo>Deploying messages from ${message.project.dir} to ${component.release.dir}</echo>
        <copy todir="${component.release.dir}/bundle/system">
            <fileset dir="${message.project.dir}/build">
                <include name="**-bundle.jar" />
            </fileset>
        </copy>
    </target>

    <!-- ************************** components projects *************************** -->

    <target name="build-components">
        <antcall target="build-component-project" inheritrefs="true">
            <param name="component.project.dir" value="../subProject/subProject.mw.msg.broker" />
        </antcall>
        <foreach target="build-component-project" param="component.project.dir" inheritrefs="true">
            <path refid="component.projects" />
        </foreach>
    </target>

    <target name="build-component-project">
        <basename file="${component.project.dir}" property="component.name" />
        <property name="component.release.dir" value="${install.dir}/${component.name}" />
        <if>
            <available file="${component.project.dir}/build.xml" />
            <then>
                <echo message="Building component project: ${component.name}" />

                <!-- build the component -->
                <ant dir="${component.project.dir}" antfile="build.xml" />

                <!-- copy the component bundles -->
                <copy todir="${component.release.dir}/bundle/component" flatten="true">
                    <fileset dir="${component.project.dir}/build">
                        <include name="**/*-bundle.jar" />
                    </fileset>
                </copy>

                <!-- copy the message bundles -->
                <antcall target="deploy-messages" inheritrefs="true" inheritall="true" />

                <!-- copy the project bundles -->
                <antcall target="deploy-bundles" inheritrefs="true" inheritall="true" />

                <!-- copy the system bundles -->
                <copy todir="${component.release.dir}/bundle">
                    <fileset dir="${base.dir}/bundle" includes="**" />
                </copy>
                <copy file="../subProject/org.snake.yaml/build/org.snake.yaml-bundle.jar" todir="${component.release.dir}/bundle/system" />
                <copy file="../subProject/org.apache.activemq/build/org.apache.activemq-bundle.jar" todir="${component.release.dir}/bundle/system" />
                <copy file="../subProject/com.google.protobuf/build/com.google.protobuf-bundle.jar" todir="${component.release.dir}/bundle/system" />
                <copy file="../subProject/subProject.cmd.felix/build/subProject.cmd.felix-bundle.jar" todir="${component.release.dir}/bundle/component" />

                <!-- copy felix binary bundle -->
                <copy file="../subProject/org.apache.felix/felix.jar" todir="${component.release.dir}/bin" />


                <!-- copy template files and configurations -->
                <if>
                    <available file="${component.project.dir}/conf/config.properties" />
                    <then>
                        <copy file="${component.project.dir}/conf/config.properties" todir="${component.release.dir}/conf" />
                    </then>
                    <else>
                        <echo message="${component.project.dir} does not provide a bundle config - using default from release bundle" />
                        <copy file="${template.dir}/config.properties" todir="${component.release.dir}/conf" />
                    </else>
                </if>
                <if>
                    <available file="${component.project.dir}/plans" type="dir" />
                    <then>
                        <copy todir="${component.release.dir}/plans">
                            <fileset dir="${component.project.dir}/plans" includes="**" />
                        </copy>
                    </then>
                </if>
                <copy file="../subProject/subProject.mw/conf/log4j.xml" todir="${component.release.dir}/conf" />
                <copy file="${template.dir}/run.ant" todir="${component.release.dir}" />
                <copy file="${template.dir}/run.sh" todir="${component.release.dir}" />
            </then>
            <else>
                <echo message="Skipping component project due to missing build.xml in: ${component.project.dir} " />
            </else>
        </if>
    </target>

    <target name="deploy" depends="clean, prepare, build-subProject, build-messages, build-bundles, build-components" />

    <target name="forbidden">
        <echo>Sorry, this script is only to be called externally. Please read how to create a new project release in the redmine wiki!</echo>
    </target>

</project>

注意它给出错误的部分:

<copy todir="${component.release.dir}/bundle">
    <fileset dir="${base.dir}/bundle" includes="**" />
</copy>

如果您需要build.xml和build.all.xml文件,那么它们是:

build.all.xml

<?xml version="1.0" encoding="UTF-8"?>
<project basedir="." default="all" name="subProject.mw.build.all">

    <!-- ************************************************************** -->
    <!-- **************************initial names*********************** -->
    <!-- ************************************************************** -->
    <property file="build.properties" />

    <!-- utilize predefined environment variables -->
    <property file="ant.properties" />

    <!-- project name -->
    <property name="project.name" value="subProject.mw" />
    <property name="subProject.mw.dir" value="../subProject.mw" />

    <!-- specify bundles to build. The bundles name is separated with "," without space.  -->
    <!-- For example: <property name="bundles" value="base,bundle1,bundle2,bundle3" />    -->
    <!-- The order of bundles should follow their dependencies                            -->
    <property name="system-bundles" value="health" />
    <!-- <property name="component-bundles" value="" />  value="msg.broker" /> -->


    <!-- this library requires the subProject.mw project parallel to this project -->
    <taskdef resource="net/sf/antcontrib/antcontrib.properties">
        <classpath>
            <pathelement location="${subProject.mw.dir}/tools/ant/ant-contrib.jar" />
        </classpath>
    </taskdef>

    <path id="module.classpath">
        <path refid="basic.classpath" />
        <pathelement location="log4j-1.2.17.jar" />
        <pathelement location="../org.apache.felix/felix.jar" />
    </path>


    <!-- build -->
    <property name="build.dir" value="build" />


    <!-- ************************************************************** -->
    <!-- *******************initial names for the sources directories** -->
    <!-- ************************************************************** -->

    <property name="src" value="./src" />
    <property name="release.file" value="./${project.name}-bundle.jar" />
    <property name="release.dir" value="./release/${project.name}" />
    <property name="release.bundle.dir" value="${release.dir}/bundle" />

    <!-- ************************************************************** -->
    <!-- *******************initial names for classes****************** -->
    <!-- ************************************************************** -->

    <!-- common compiled classes-->
    <property name="common.classes.dir" value="${build.dir}" />


    <!-- ************************************************************** -->
    <!-- *************************class path*************************** -->
    <!-- ************************************************************** -->

    <path id="basic.classpath">
        <pathelement location="." />
    </path>

    <path id="module.classpath">
        <path refid="basic.classpath" />
    </path>


    <!-- ************************************************************** -->
    <!-- *************************PREPARE****************************** -->
    <!-- ************************************************************** -->
    <!-- removes all generated files and directories -->
    <target name="clean">
        <echo message="Cleaning Files" />
        <delete file="${release.file}" />
        <delete dir="${release.dir}" />
        <delete dir="${release.bundle.dir}" />
    </target>

    <!-- simple initializing -->
    <target name="init" depends="clean">
        <echo message="${project.name}" />
    </target>

    <!-- prepares any build target by creating the expected directory structure -->
    <target name="prepare" depends="init">
        <!-- create the time stamp -->
        <tstamp />
        <mkdir dir="build" />
        <mkdir dir="${release.dir}" />
        <mkdir dir="${release.bundle.dir}" />
    </target>


    <!-- ************************************************************** -->
    <!-- *************************COMPILE****************************** -->
    <!-- ************************************************************** -->

    <target name="build-bundle">
        <echo>Building system bundle: ${bundle}</echo>
        <ant inheritall="false" dir="../subProject.mw.${bundle}" antfile="build.xml" target="all" />
    </target>

    <target name="build-mw-system-bundle" depends="build-bundle">
        <copy file="../subProject.mw.${bundle}/build/subProject.mw.${bundle}-bundle.jar" tofile="./bundle/system/subProject.mw.${bundle}-bundle.jar" />
    </target>

    <target name="build-mw">
        <ant inheritall="false" dir="./" antfile="build.xml" target="all" />
        <copy file="./build/subProject.mw-bundle.jar" tofile="./bundle/system/subProject.mw-bundle.jar" />
    </target>

    <target name="build-msg">
        <ant inheritall="false" dir="../subProject.msg" antfile="build.xml" target="all" />
        <copy file="../subProject.msg/build/subProject.msg-bundle.jar" tofile="./bundle/system/subProject.msg-bundle.jar" />
    </target>

    <target name="build-mw-bundles" depends="prepare, build-msg, build-essentials, build-mw">
        <foreach parallel="true" inheritall="false" list="${system-bundles}" param="bundle" target="build-mw-system-bundle" />
        <!-- <foreach parallel="true" inheritall="false" list="${component-bundles}" param="bundle" target="build-mw-component-bundle" /> -->
    </target>

    <target name="build-essentials">
        <ant inheritall="false" dir="../org.apache.activemq" antfile="build.xml" target="all" />
        <ant inheritall="false" dir="../org.snake.yaml" antfile="build.xml" target="all" />
        <ant inheritall="false" dir="../com.google.protobuf" antfile="build.xml" target="all" />
        <ant inheritall="false" dir="../subProject.msg" antfile="build.xml" target="all" />
        <ant inheritall="false" dir="../org.apache.log4j" antfile="build.xml" target="all" />
        <ant inheritall="false" dir="../subProject.cmd.felix" antfile="build.xml" target="all" />
    </target>

    <!-- ************************************************************** -->
    <!-- *************************ALL********************************** -->
    <!-- ************************************************************** -->

    <target name="all" depends="build-mw-bundles">
        <echo message="BUILDING ${project.name} FINISHED" />
    </target>

</project>

的build.xml

<?xml version="1.0" encoding="UTF-8"?>
<project basedir="." default="all" name="subProject.mw.build">

    <!-- ************************************************************** -->
    <!-- **************************initial names*********************** -->
    <!-- ************************************************************** -->
    <property file="build.properties" />

    <!-- utilize predefined environment variables -->
    <property file="ant.properties" />

    <!-- project name -->
    <basename property="project.name" file="." />
    <echo>Running build.xml from ${project.name}</echo>

    <!-- build -->
    <property name="build.dir" value="build" />
    <property name="bin.dir" value="bin" />

    <!-- ************************************************************** -->
    <!-- *******************initial names for the sources directories** -->
    <!-- ************************************************************** -->

    <property name="src" value="./src" />
    <property name="release.file" value="./${project.name}-bundle.jar" />

    <!-- ************************************************************** -->
    <!-- *******************initial names for classes****************** -->
    <!-- ************************************************************** -->


    <!-- ************************************************************** -->
    <!-- *************************class path*************************** -->
    <!-- ************************************************************** -->

    <path id="basic.classpath">
        <pathelement location="." />
    </path>

    <path id="module.classpath">
        <path refid="basic.classpath" />
        <pathelement location="../com.google.protobuf/protobuf-java-2.5.0.jar" />
        <pathelement location="../org.snake.yaml/snakeyaml-1.13.jar" />
        <pathelement location="../org.apache.activemq/activemq-all-5.9.0.jar" />
        <pathelement location="../subProject.msg/build/subProject.msg-bundle.jar" />
        <pathelement location="../org.apache.felix/felix.jar" />
        <pathelement location="../org.apache.log4j/build/org.apache.log4j-bundle.jar" />
    </path>

    <pathconvert property="classpathProp" refid="module.classpath" />
    <echo>Classpath is: ${classpathProp}</echo>


    <!-- ************************************************************** -->
    <!-- *************************PREPARE****************************** -->
    <!-- ************************************************************** -->
    <!-- removes all generated files and directories -->
    <target name="clean">
        <echo message="Cleaning Files" />
        <delete dir="${build.dir}" />
        <delete dir="${release.dir}" />
    </target>

    <!-- simple initializing -->
    <target name="init" depends="clean">
        <echo message="${project.name}" />
    </target>

    <!-- prepares any build target by creating the expected directory structure -->
    <target name="prepare" depends="init">
        <!-- create the time stamp -->
        <tstamp />
        <mkdir dir="${bin.dir}" />
        <mkdir dir="${build.dir}" />
    </target>


    <!-- ************************************************************** -->
    <!-- *************************COMPILE****************************** -->
    <!-- ************************************************************** -->

    <target name="compile-common" depends="prepare">
        <javac includeantruntime="false" destdir="${bin.dir}" source="${compiler.source}" target="${compiler.target}" debug="${compiler.debug}" deprecation="${compiler.deprecation}" optimize="${compiler.optimize}" debuglevel="${compiler.debuglevel}" encoding="${compiler.encoding}">
            <src path="${src}" />
            <classpath>
                <path refid="module.classpath" />
            </classpath>
            <include name="**/*.java" />
        </javac>
    </target>


    <target name="jar-common" depends="compile-common">
        <jar manifest="./META-INF/MANIFEST.MF" jarfile="${build.dir}/${release.file}" basedir="${bin.dir}">
            <!--
            <zipfileset src="../org.snake.yamle/snakeyaml-1.13.jar" includes="**/*.class META-INF/**" />
            <zipfileset src="../org.activemq/activemq-all-5.9.0.jar" includes="**/*.class META-INF/**" />
            -->
        </jar>

    </target>


    <!-- ************************************************************** -->
    <!-- *************************ALL********************************** -->
    <!-- ************************************************************** -->

    <target name="all"  depends="jar-common"> 
        <echo message="BUILDING ${project.name} FINISHED" />
    </target>

</project>

0 个答案:

没有答案