ant:无法创建任务或类型

Rus*_*man 13 ant

(是的,我已根据本论坛和JavaRanch等许多其他类似问题的答案阅读和播放 - 但尚无用.)

我根据Apache doc创建了一个自定义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)
Run Code Online (Sandbox Code Playgroud)

这符合我的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>
Run Code Online (Sandbox Code Playgroud)

我在路径*$ ANT_HOME/lib*上有ant-contrib-1.0b3.jar.我在该路径上有sqlscriptpreprocessor.jar,以及我的构建的本地类路径.

为了驱除这个问题,我尝试了以下一组语句的每个组合,我通过谷歌在整个地方找到了这些语句,这意味着<taskdef ant-contrib>中的一个与<taskdef之一sqlscriptpreprocessor> constructs,第一个中的两个,后者中的一个,第一个中的两个,后者中的两个,所有在一起,没有一个,等等.

<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>
Run Code Online (Sandbox Code Playgroud)

令人沮丧的是,它并不像他们所说的那样容易向蚂蚁添加自定义任务.

我将非常感谢任何和所有评论.

谢谢,

拉斯

Rus*_*man 16

我现在已经挣扎了两天了.我似乎得到的答案是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>
Run Code Online (Sandbox Code Playgroud)

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

我很抱歉回答了我自己的问题; 它发生在一两次之前,对我来说似乎很蹩脚.我希望它可以帮助别人.

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

  • 这不是蹩脚的.你应该尽可能接受你的答案. (14认同)