ant:创建任务或类型失败 [英] ant: failed to create task or type

查看:84
本文介绍了ant:创建任务或类型失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

(Yes, I've read and played around based on answers to similar questions in this forum and in many others such as JavaRanch--to no avail yet.)

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

I've created a custom ant task according to Apache doc.

运行蚂蚁,我得到:

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 文件中的一个目标:

This is pursuant to a target in my build.xml file:

<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,以及我构建的本地类路径.

I have ant-contrib-1.0b3.jar on the path *$ANT_HOME/lib*. I have sqlscriptpreprocessor.jar on that path, plus the local classpath for my build.

为了解决这个问题,我尝试了以下语句的所有组合,这些语句是我通过 Google 到处收集的,意思是 之一.使用 之一构造,第一个与后者的一个,第一个与后者的两个,所有在一起,没有一个,等等.

In an attempt to exorcise this problem, I've tried every combination of the following set of statements, which I've picked up all over the place via Google, meaning one of the <taskdef ant-contrib> with one of the <taskdef sqlscriptpreprocessor> constructs, two of the first with one of the latter, one of the first with two of the latter, all together, none of them, etc.

<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 添加自定义任务并不像他们说的那么容易.

It's frustrating that it's not as easy as they say to add custom tasks to ant.

我将不胜感激任何和所有评论.

I would greatly appreciate any and all comments.

谢谢,

罗斯

推荐答案

我已经为此纠结了两天.我似乎得到的答案是 http://ant.apache.org/manual/tutorial-写作-tasks.html:

I've struggled with this for two days now. The answer I appear to be getting is implied by http://ant.apache.org/manual/tutorial-writing-tasks.html:

<taskdef name="sqlscriptpreprocessor" ...>元素必须放在使用它的目标内,在这种情况下,mysql-preprocess.我不是在做这个.现在,我有:

The <taskdef name="sqlscriptpreprocessor" ...> element must be placed down inside the target that uses it, in this case, mysql-preprocess. I was not doing this. Now, I have:

<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>

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

I don't understand why my custom task must be defined in the target element that consumes it, but this is fine by me. I'm not certain this is couched as gracefully as it could be, but it works now.

很抱歉回答我自己的问题;它以前发生过一两次,我似乎很蹩脚.我只是希望它可以帮助其他人.

I'm sorry for answering my own question; it's happened before once or twice and it seems pretty lame of me. I just hope it helps someone else.

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

Thanks for all the replies surrounding this topic in all the forums and posts I read over the last two days.

这篇关于ant:创建任务或类型失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆