ANT:使用条件标签,

发布于 2024-11-15 01:07:56 字数 1034 浏览 0 评论 0原文

我想做这样的事情

<target name="clean" description="clean">
    <if>
        <available file="${build}" type="dir" />
        <then>
            <delete dir="${build}" />
        </then>
    </if>
</target>

按照 建议 在 stackoverflow.com 上找到,我下载了 ant-contrib-1.0b3.jar 并将其放入我的路径

Classpath

另外,在 Ant Build 配置下的类路径中,我有 在此处输入图像描述

运行 ANT 脚本时,我仍然得到

BUILD FAILED
C:\Repositories\blah\build.xml:60: Problem: failed to create task or type if
Cause: The name is undefined.
Action: Check the spelling.
Action: Check that any custom tasks/types have been declared.
Action: Check that any <presetdef>/<macrodef> declarations have taken place.

我缺少什么?请指教

I would like to do something like this

<target name="clean" description="clean">
    <if>
        <available file="${build}" type="dir" />
        <then>
            <delete dir="${build}" />
        </then>
    </if>
</target>

As per suggestions found on stackoverflow.com, i downloaded ant-contrib-1.0b3.jar and put it into my path

Classpath

Additionally, under Ant Build configuration, in classpath, i have
enter image description here

When running my ANT script, i still get

BUILD FAILED
C:\Repositories\blah\build.xml:60: Problem: failed to create task or type if
Cause: The name is undefined.
Action: Check the spelling.
Action: Check that any custom tasks/types have been declared.
Action: Check that any <presetdef>/<macrodef> declarations have taken place.

What am i missing? Please advise

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

迷爱 2024-11-22 01:07:56

或者,一次可以在您的 ANT 脚本中包含以下行

<taskdef resource="net/sf/antcontrib/antlib.xml" />

只要 ant-contribs 在您的路径中,就不需要其他任何东西

这个解决方案更干净一点,因为一个获得了对 ALL 的访问权限标签, 不仅仅是手动指定的标签

Alternately, once can include the following line in your ANT script

<taskdef resource="net/sf/antcontrib/antlib.xml" />

As long as ant-contribs is in your path, nothing else is needed

This solution is a bit cleaner, as one gains access to ALL the tags, not just the ones manually specified

木格 2024-11-22 01:07:56

同样的问题就这样解决了。
我在 buid XML 文件的开头放置了以下几行:

<taskdef resource="net/sf/antcontrib/antlib.xml">
  <classpath>
    <pathelement location="your/path/to/ant-contrib-${version}.jar" />
  </classpath>
</taskdef>

Same issue resolved in that way.
I put at the start of the buid XML file the following lines:

<taskdef resource="net/sf/antcontrib/antlib.xml">
  <classpath>
    <pathelement location="your/path/to/ant-contrib-${version}.jar" />
  </classpath>
</taskdef>
梦回旧景 2024-11-22 01:07:56

标准的 ant 方式类似于=

 <target name="check">
  <condition property="delbuild">
    <available file="${build}" type="dir"/>
  </condition>
 </target>

 <target name="delbuild" depends="check" if="delbuild">
 <delete dir="${build}"/>
    <!-- .. -->
 </target>

带有 Ant 插件 Flaka 的代码片段,这是最近的替代方案到 antcontrib。像往常一样通过
Preferences | 在 Eclipse 中安装蚂蚁 |运行时 |全球条目 | ant-flaka-1.02.-1.02.jar =

<project xmlns:fl="antlib:it.haefelinger.flaka">
  <!-- some standalone if construct -->
  <fl:when test=" '${build}'.isdir ">
    <delete dir="${build}"/>
  </fl:when>

    <!-- some if/then/else construct -->
    <fl:choose>
     <!-- if -->
     <when test=" '${buildtype}' eq 'prod' ">
        <!-- then -->
        <echo>..starting ProductionBuild</echo>
     </when>
     <when test=" '${buildtype}' eq 'test' ">
        <!-- then -->
    <echo>..starting TestBuild</echo>
   </when>
    <!-- else -->
     <otherwise>
      <fl:unless test="has.property.dummybuild">
       <fail message="No valid buildtype !, found => '${buildtype}'"/>
      </fl:unless>
        <echo>.. is DummyBuild</echo>
     </otherwise>
    </fl:choose>
</project>

输出ant -f build.xml -Dbuildtype=prod 或
ant -f build.xml -Dbuildtype=prod -Ddummybuild=任何

[echo] ..starting ProductionBuild

有拼写错误的输出 => ant - build.xml -Dbuildtype=testt

BUILD FAILED
/home/rosebud/workspace/AntTest/build.xml:21: No valid buildtype !, found => 'testt'

输出 ant -f build.xml -Ddummybuild=whatever

[echo] .. is DummyBuild

The standard ant way would be something like =

 <target name="check">
  <condition property="delbuild">
    <available file="${build}" type="dir"/>
  </condition>
 </target>

 <target name="delbuild" depends="check" if="delbuild">
 <delete dir="${build}"/>
    <!-- .. -->
 </target>

A snippet with the Ant Plugin Flaka, a recent alternative to antcontrib. Installation in Eclipse as usual via
Preferences | Ant | Runtime | Global Entries | ant-flaka-1.02.-1.02.jar =

<project xmlns:fl="antlib:it.haefelinger.flaka">
  <!-- some standalone if construct -->
  <fl:when test=" '${build}'.isdir ">
    <delete dir="${build}"/>
  </fl:when>

    <!-- some if/then/else construct -->
    <fl:choose>
     <!-- if -->
     <when test=" '${buildtype}' eq 'prod' ">
        <!-- then -->
        <echo>..starting ProductionBuild</echo>
     </when>
     <when test=" '${buildtype}' eq 'test' ">
        <!-- then -->
    <echo>..starting TestBuild</echo>
   </when>
    <!-- else -->
     <otherwise>
      <fl:unless test="has.property.dummybuild">
       <fail message="No valid buildtype !, found => '${buildtype}'"/>
      </fl:unless>
        <echo>.. is DummyBuild</echo>
     </otherwise>
    </fl:choose>
</project>

output with ant -f build.xml -Dbuildtype=prod or
ant -f build.xml -Dbuildtype=prod -Ddummybuild=whatever

[echo] ..starting ProductionBuild

output with typo => ant - build.xml -Dbuildtype=testt

BUILD FAILED
/home/rosebud/workspace/AntTest/build.xml:21: No valid buildtype !, found => 'testt'

output with ant -f build.xml -Ddummybuild=whatever

[echo] .. is DummyBuild
旧伤慢歌 2024-11-22 01:07:56

我遇到了同样的问题。我按照以下方式解决了。
有时这可能是兼容性问题。

  • 右键单击 build.xml。
  • 转到“运行方式”--> 2 Ant... 选择 Classpath 选项卡检查 Ant Home 版本(有时 eclipse 选择默认的 ant 版本)。
  • 如果列出的版本不同,则更改 Ant Home Classpath
    到C:\XXXX\ant\XXX
  • 最后点击User Entries -->添加外部 JARS..-->添加
    ant-contrib.xxjar 位于 C:\XXXX\ant\XXX\ant-contrib\ 目录中。

I got the same issue. I resolved in the following way.
Sometimes this might be compatibility problem.

  • Right click on build.xml.
  • Go to "Run As" --> 2 Ant... Select Classpath tab check Ant Home version (Sometimes eclipse selects default ant version).
  • If the version listed is different, then change Ant Home Classpath
    to C:\XXXX\ant\X.X.X.
  • Finally click on the User Entries --> Add External JARS..--> add
    ant-contrib.x.x.jar form C:\XXXX\ant\X.X.X\ant-contrib\ directory.
各自安好 2024-11-22 01:07:56

在 Ant 运行时的任务选项卡上,您是否看到“if”任务?

On the tasks tab for your Ant Runtime do you see the 'if' task?

所谓喜欢 2024-11-22 01:07:56

导出 ANT_HOME=/path/to/ant/apache-ant-1.8.2

在正确设置 ANT_HOME 之前我无法让它工作。 Java 不断挑选安装在盒子上的另一只蚂蚁。

export ANT_HOME=/path/to/ant/apache-ant-1.8.2

I couldn't get it to work until I had ANT_HOME set properly. Java kept picking another ant installed on the box.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文