Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/ant/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在ant中,如何创建和使用';图书馆';目标数量?_Ant - Fatal编程技术网

在ant中,如何创建和使用';图书馆';目标数量?

在ant中,如何创建和使用';图书馆';目标数量?,ant,Ant,为了消除antbuild.xml文件中的冗余,我决定将重复的目标分解到mytargets.xml文件中,将其发布到工件库,然后按以下方式导入: <import> <url url="http://mycompany.com/artifacts/mycompany.com/mytargets/1.2.3/mytargets-1.2.3.xml"/> </import> 但是,正如您可能已经猜到的,在以这种方式调整我的后,我甚至无法执行我的设置我的目标,

为了消除ant
build.xml
文件中的冗余,我决定将重复的目标分解到
mytargets.xml
文件中,将其发布到工件库,然后按以下方式导入:

<import>
    <url url="http://mycompany.com/artifacts/mycompany.com/mytargets/1.2.3/mytargets-1.2.3.xml"/>
</import>
但是,正如您可能已经猜到的,在以这种方式调整我的
后,我甚至无法执行我的
设置
我的目标,因为该文件尚不存在:

Buildfile: /home/me/myproject/build.xml

BUILD FAILED
/home/me/myproject/build.xml:265: Cannot find /home/me/myproject/antlib/mytargets/mytargets.xml imported from /home/me/myproject/build.xml
optional=“true”
添加到
只会将问题推迟到依赖于
mytargets.xml的第一个目标

我查看了,但这种方法似乎不允许您定义


那么,人们如何在多个项目中共享AntXML呢?我已经在用“唯一正确的方法”了吗?或者,有更好的方法吗?

如果您主要是想避免在已有本地副本的情况下下载远程副本,您可以尝试以下方法:

<condition property="mytargets.xml.available">
    <available file="${basedir}/antlib/mytargets/mytargets.xml" />
</condition>

<target name="setup" unless="mytargets.xml.available">
    <get
        src="http://mycompany.com/artifacts/mycompany.com/mytargets/1.2.3/mytargets-1.2.3.xml"
        dest="${basedir}/antlib/mytargets"
    />
</target>

<target name="main" depends="setup">
    <import file="${basedir}/antlib/mytargets/mytargets.xml" />

    ...
</target>

...

因此,在我看来,
本质上是本地的,不打算重用。另一方面,
似乎是为了重用

这是“库”
mymacros.xml

<?xml version="1.0"?>
<antlib>
    <macrodef name="mymacro">
        ...
    </macrodef>
</antlib>
<?xml version="1.0"?>
<project name="myproject">
    <target name="mytarget">
        <mymacro/>
    </target>
    <taskdef file="mymacros.xml"/>
</project>

不同,
不会在缺少
mymacros.xml
时立即导致构建失败,这给了您下载它的机会。

不,下载文件并导入它实际上是个鸡蛋问题。看起来您“只是不这样做”。。。
<?xml version="1.0"?>
<project name="myproject">
    <target name="mytarget">
        <mymacro/>
    </target>
    <taskdef file="mymacros.xml"/>
</project>