2011-11-01 32 views
10

(是的,我已经阅读并发挥各地根据答案,在这个论坛类似的问题,在许多其他如JavaRanch的 - 没有用呢。)蚂蚁:无法创建任务或键入

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

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

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

为了驱除这个问题,我尝试了以下一组语句的所有组合,这些语句是我通过Google搜集到的,意思是< taskdef ant-contrib >其中一个在<的taskdef sqlscriptpreprocessor >结构中,两个第一与后者的一个,两个,后者的第一个,都在一起,他们没有等

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

这是令人沮丧,这不是因为很容易,因为他们说为蚂蚁增加自定义任务。

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

感谢,

拉斯

回答

14

我这个现在挣扎了两天。我出现这个问题的答案可以得到由http://ant.apache.org/manual/tutorial-writing-tasks.html暗示:

的< 的taskdef名=“sqlscriptpreprocessor” ... >元素必须放在下来使用它的目标里面,在这种情况下,的mysql-预处理。我没有这样做。现在,我有:

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

我不明白为什么我的自定义任务必须在消耗它的目标元素来定义,但这是没意见。我不确定这是如何优雅,但它现在起作用。

我很抱歉回答我自己的问题;它曾经发生过一两次,看起来很蹩脚。我只希望它能帮助别人。

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

+12

这不是跛脚。你应该尽可能接受你的答案。 – FailedDev

1

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

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