【问题标题】:ant: failed to create task or typeant:创建任务或类型失败
【发布时间】:2011-12-19 15:32:05
【问题描述】:

(是的,我已经阅读并根据对本论坛和许多其他论坛(例如 JavaRanch)中类似问题的回答进行了尝试,但无济于事。)

我根据 Apache 文档创建了一个自定义的 ant 任务。

跑蚂蚁,我明白了:

BUILD FAILED
/home/russ/blackpearl/fun/build.xml:121: Problem: failed to create task or type sqlscriptpreprocessor
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.
at org.apache.tools.ant.UnknownElement.getNotFoundException(UnknownElement.java:487)
at org.apache.tools.ant.UnknownElement.makeObject(UnknownElement.java:419)
at org.apache.tools.ant.UnknownElement.maybeConfigure(UnknownElement.java:163)
at org.apache.tools.ant.Task.perform(Task.java:347)

这是根据我的 build.xml 文件中的一个目标:

<target name="mysql-preprocess"
        description="Preprocess MySQL database scripts into one file">
    <sqlscriptpreprocessor inputfilepath="${basedir}/extras/blackpearl.sql.in"
                          outputfilepath="${basedir}/extras/blackpearl.sql" />
</target>

我在路径 *$ANT_HOME/lib* 上有 ant-contrib-1.0b3.jar。我在那个路径上有 sqlscriptpreprocessor.jar,还有我构建的本地类路径。

为了解决这个问题,我尝试了以下一组语句的每种组合,这些语句是我通过谷歌到处收集的,意思是 之一与 构造,第一个中的两个与后者中的一个,第一个中的一个与后者中的两个,一起,没有一个,等等。

<taskdef resource="net/sf/antcontrib/antlib.xml" />
<taskdef resource="net/sf/antcontrib/antcontrib.properties" />
<taskdef resource="net/sf/antcontrib/antcontrib.properties">
    <classpath>
        <pathelement location="/home/russ/dev/downloads/ant-contrib/ant-contrib-1.0b3.jar" />
    </classpath>
</taskdef>

<taskdef name="sqlscriptpreprocessor" classname="com.etretatlogiciels.ant.task.SqlScriptPreprocessor" />
<taskdef resource="${basedir}/lib/ant-tasks/SqlScriptPreprocessor.properties"
         classpath="${basedir}/lib/ant-tasks/sqlscriptpreprocessor.jar" />
<taskdef resource="${basedir}/lib/ant-tasks/SqlScriptPreprocessor.properties">
    <classpath>
        <pathelement location="${basedir}/lib/ant-tasks/sqlscriptpreprocessor.jar" />
    </classpath>
</taskdef>

令人沮丧的是,给ant添加自定义任务并没有他们说的那么容易。

我将非常感谢所有 cmets。

谢谢,

罗斯

【问题讨论】:

    标签: ant


    【解决方案1】:

    我已经为此苦苦挣扎了两天。 http://ant.apache.org/manual/tutorial-writing-tasks.html 暗示了我似乎得到的答案:

    taskdef name="sqlscriptpreprocessor" ...> 元素必须放在使用它的目标中,在本例中为 mysql-preprocess。我没有这样做。现在,我有:

    <target name="mysql-preprocess"
            description="Preprocess MySQL database scripts into one file">
        <taskdef name="sqlscriptpreprocessor"
                 classname="com.etretatlogiciels.ant.task.SqlScriptPreprocessor"
                 classpath="${basedir}/lib/ant-tasks/sqlscriptpreprocessor.jar" />
        <sqlscriptpreprocessor inputfilepath="${basedir}/extras/blackpearl.sql.in"
                              outputfilepath="${basedir}/extras/blackpearl.sql" />
    </target>
    

    我不明白为什么我的自定义任务必须在使用它的目标元素中定义,但这对我来说很好。我不确定这是否尽可能优雅地表达,但现在可以了。

    很抱歉回答了我自己的问题;它曾经发生过一次或两次,我似乎很蹩脚。我只是希望它可以帮助别人。

    感谢我在过去两天阅读的所有论坛和帖子中围绕此主题的所有回复。

    【讨论】:

      【解决方案2】:

      在构建文件中添加下一行解决了问题:

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

      【讨论】:

        【解决方案3】:

        对我来说这条消息:

        /Users/packrd/Downloads/source/build.xml:435: The following error occurred while executing this line:
        /Users/packrd/Downloads/source/build.xml:440: The following error occurred while executing this line:
        /Users/packrd/Downloads/source/Documentation/docs/build.xml:221: The following error occurred while executing this line:
        /Users/packrd/Downloads/source/Documentation/docs/asciidoc-macros.xml:249: Problem: failed to create task or type antlib:net.sf.antcontrib:switch
        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.
        No types or tasks have been defined in this namespace yet
        
        This appears to be an antlib declaration. 
        Action: Check that the implementing library exists in one of:
                -/usr/local/Cellar/ant/1.10.8/libexec/lib
                -/Users/packrd/.ant/lib
                -a directory added on the command line with the -lib argument
        

        意味着我没有安装 ant-contrib,在 OS X 上修复:

        brew install ant-contrib

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2015-08-11
          • 2015-12-14
          • 2015-11-18
          • 2012-03-28
          • 1970-01-01
          • 2011-09-15
          相关资源
          最近更新 更多