具有顺序 ant-contrib 的 Maven antrun 无法运行
我们有一个特殊的例程将子文件夹中的文件分解为扩展名,这些扩展名将被复制并打包为单个扩展文件。对于这种特殊的方法,我想使用maven-antrun-plugin,为了通过dirset进行顺序迭代和jar打包,我们需要库ant-contrib。
即将推出的插件配置失败并出现错误。我配置错误了什么?谢谢。
插件配置
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.6</version>
<executions>
<execution>
<phase>validate</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<target>
<for param="extension">
<path>
<dirset dir="${basedir}/src/main/webapp/WEB-INF/resources/extensions/">
<include name="*" />
</dirset>
</path>
<sequential>
<basename property="extension.name" file="${extension}" />
<echo message="Creating JAR for extension '${extension.name}'." />
<jar destfile="${basedir}/target/extension-${extension.name}-1.0.0.jar">
<zipfileset dir="${extension}" prefix="WEB-INF/resources/extensions/${extension.name}/">
<include name="**/*" />
</zipfileset>
</jar>
</sequential>
</for>
</target>
</configuration>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>ant-contrib</groupId>
<artifactId>ant-contrib</artifactId>
<version>1.0b3</version>
<exclusions>
<exclusion>
<groupId>ant</groupId>
<artifactId>ant</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.apache.ant</groupId>
<artifactId>ant-nodeps</artifactId>
<version>1.8.1</version>
</dependency>
</dependencies>
</plugin>
错误
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-antrun-plugin:1.6:run (default) on project extension-platform: An Ant BuildException has occured: Problem: failed to create task or type for
[ERROR] Cause: The name is undefined.
[ERROR] Action: Check the spelling.
[ERROR] Action: Check that any custom tasks/types have been declared.
[ERROR] Action: Check that any <presetdef>/<macrodef> declarations have taken place.
[ERROR] -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException
We have a special routine to explode files in a subfolder into extensions, which will be copied and jared into single extension files. For this special approach I wanted to use the maven-antrun-plugin
, for the sequential iteration and jar packaging through the dirset, we need the library ant-contrib.
The upcoming plugin configuration fails with an error. What did I misconfigured? Thank you.
Plugin configuration
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.6</version>
<executions>
<execution>
<phase>validate</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<target>
<for param="extension">
<path>
<dirset dir="${basedir}/src/main/webapp/WEB-INF/resources/extensions/">
<include name="*" />
</dirset>
</path>
<sequential>
<basename property="extension.name" file="${extension}" />
<echo message="Creating JAR for extension '${extension.name}'." />
<jar destfile="${basedir}/target/extension-${extension.name}-1.0.0.jar">
<zipfileset dir="${extension}" prefix="WEB-INF/resources/extensions/${extension.name}/">
<include name="**/*" />
</zipfileset>
</jar>
</sequential>
</for>
</target>
</configuration>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>ant-contrib</groupId>
<artifactId>ant-contrib</artifactId>
<version>1.0b3</version>
<exclusions>
<exclusion>
<groupId>ant</groupId>
<artifactId>ant</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.apache.ant</groupId>
<artifactId>ant-nodeps</artifactId>
<version>1.8.1</version>
</dependency>
</dependencies>
</plugin>
Error
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-antrun-plugin:1.6:run (default) on project extension-platform: An Ant BuildException has occured: Problem: failed to create task or type for
[ERROR] Cause: The name is undefined.
[ERROR] Action: Check the spelling.
[ERROR] Action: Check that any custom tasks/types have been declared.
[ERROR] Action: Check that any <presetdef>/<macrodef> declarations have taken place.
[ERROR] -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
因此我浪费了至少一个小时来找到下面的一点提示错误...
我使用maven3和其余的如上所述,但我必须使用maven.dependency.classpath
而不是
maven.plugin.classpath
!否则 Maven 将找不到 contrib 任务。希望这对任何人都有帮助。Therefore I wasted at least one hour to find the error a little hint below ...
I use maven3 and the rest as described above, BUT I have to use
maven.dependency.classpath
instead of
maven.plugin.classpath
! Otherwise maven won't find the contrib tasks. Hope this helps anybody.看来您缺少 taskdef 所需的 声明 ant-contrib 任务,以便 Ant 了解它们,因此这部分错误消息:(
可能是如果失败的任务 -
'for'
- 被引用的话会更清楚一些。)添加 taskdef 的一种方法是将其插入到
for
循环之前:It looks like you're missing the taskdef that's needed to declare the ant-contrib tasks, so that Ant knows about them, hence this part of the error message:
(It would perhaps be a little clearer if the failed task -
'for'
- were quoted.)One way to add the taskdef is to insert it immediately prior to the
for
loop:在浪费了 2 个小时并阅读了太多答案之后,这就是我需要检查的
http://www.thinkplexx.com/learn/howto/maven2/plugins/could-not-load-definitions -from-resource-antlib-xml-understanding-the-problem-and-fix-worklow
我使用它打印了所有 Maven 类路径
,并检查了哪个类路径包含 antrib jar 文件。所以我将
classpathhref
从maven.plugin.classpath
更改为maven.runtime.classpath
。所以我的
taskdef
是和依赖项
After wasting 2 hours and reading too many answers, this is what I need to check
http://www.thinkplexx.com/learn/howto/maven2/plugins/could-not-load-definitions-from-resource-antlib-xml-understanding-the-problem-and-fix-worklow
I printed all the maven classpaths using this
and checked which classpath contains antrib jar file. So I changed
classpathhref
tomaven.runtime.classpath
frommaven.plugin.classpath
. So my
taskdef
isand the dependencies
我也在这个问题上浪费了几个小时,因为找不到 antcontrib
for
任务。最后,我发现
for
任务不是在antcontrib.properties
中定义的,而是在antlib.xml
中定义的!antcontrib.properties
是 ant 1.6 之前的处理方式 - 现代方式是使用antlib.xml
。所以,这是一个 maven 3.5、ant 1.8 的工作示例:
希望这会有所帮助!
I too wasted several hours on this one, because antcontrib
for
task could not be found.Finally, I found out that
for
task in not defined inantcontrib.properties
, but inantlib.xml
!antcontrib.properties
is a pre ant 1.6 way of doing things – the modern way is to useantlib.xml
.So, this is a maven 3.5, ant 1.8, working example:
Hope this helps!