(是的,我已经阅读并根据这个论坛和许多其他论坛(如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-contrib-1.0b3.jar在路径*$ANT_HOME/lib*。我在该路径上有sqlscriptpreprocessor.jar,以及构建的本地类路径。
为了解决这个问题,我尝试了下面这些语句的每一种组合,这些语句是我通过Google从各个地方收集到的,意思是"taskdef -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>
让人沮丧的是,在ant中添加自定义任务并不像他们说的那么容易。
我将非常感谢任何和所有的评论。
谢谢,
Russ
我已经纠结了两天了。我得到的答案似乎隐含在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>
我不明白为什么我的自定义任务必须在使用它的目标元素中定义,但这对我来说很好。我不确定这是否像它可能的那样优雅,但它现在工作了。
我很抱歉回答我自己的问题;以前也发生过一两次,我真是太差劲了。我只是希望它能帮助到别人。
感谢这两天来所有论坛和帖子中关于这个话题的所有回复。
在构建文件中添加下一行解决了这个问题:
<taskdef resource="net/sf/antcontrib/antlib.xml" />
我的留言:
/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