简体   繁体   English

如何在其他构建文件目标中导入一个蚂蚁构建文件

[英]how to import an ant build file inside other build file target

I have a very little knowledge about writing build files using ant targets. 我对使用ant目标编写构建文件了解甚少。 the problem i am facilng is i want to have a build file which should import other ant build file if the given condition is satisfied. 我要解决的问题是我想拥有一个构建文件,如果满足给定条件,该文件应该导入其他ant构建文件。 For suppose here in the below code if ${myresult} is set to true then the postgreswebtest.xml should be used else mysqlwebtest.xml should be used. 对于下面的代码,假设$ {myresult}设置为true,则应使用postgreswebtest.xml,否则应使用mysqlwebtest.xml。 So i tried to achieve this with the following code. 因此,我尝试通过以下代码实现这一目标。

<?xml version="1.0" encoding="utf-8" ?>

<project name="webtest" default="build" basedir=".">
        <target name="build">
        <property name="DBTYPE" value="${arg0}" />
        <echo message="${DBTYPE}" />
        <condition property="myresult">
            <equals arg1="${DBTYPE}" arg2="postgres" />
        </condition>
        <echo message="${myresult}" />
        <if>
            <isset property="myresult"/>
            <then>
                <import file="postgreswebtest.xml" />
            </then>
            <else>
                <import file="mysqlwebtest.xml" />
            </else>
        </if>
    </target>
</project>   

but when i execute this code getting the following error. 但是当我执行此代码时,出现以下错误。

BUILD FAILED: webtest.xml:21: import only allowed as a top-level task 失败:webtest.xml:21:仅允许作为顶级任务导入

Could someone please help me out with the solution 有人可以帮我解决问题吗

You can use ant ant task instead which acts as if it is imporing supplied build file. 您可以改用ant ant任务,其作用就像是在完善提供的构建文件一样。 Refer to : https://ant.apache.org/manual/Tasks/ant.html for more details. 请参阅: https : //ant.apache.org/manual/Tasks/ant.html了解更多详细信息。

With ant you can provide default target to run as well. 使用ant您还可以提供默认目标来运行。

With this approach it will conditional evaluate and import file inside your 'build' target. 通过这种方法,它将有条件地评估并导入“构建”目标中的文件。

<if>
            <isset property="myresult"/>
            <then>
                <ant antfile="postgreswebtest.xml" />
            </then>
            <else>
                <ant antfile="mysqlwebtest.xml" />
            </else>
 </if>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM