具有顺序 ant-contrib 的 Maven antrun 无法运行

发布于 2024-10-06 22:23:40 字数 3070 浏览 5 评论 0原文

我们有一个特殊的例程将子文件夹中的文件分解为扩展名,这些扩展名将被复制并打包为单个扩展文件。对于这种特殊的方法,我想使用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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

相对绾红妆 2024-10-13 22:23:40

因此我浪费了至少一个小时来找到下面的一点提示错误...

我使用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.

怪我太投入 2024-10-13 22:23:40

看来您缺少 taskdef 所需的 声明 ant-contrib 任务,以便 Ant 了解它们,因此这部分错误消息:(

Problem: failed to create task or type for

可能是如果失败的任务 - 'for' - 被引用的话会更清楚一些。)

添加 taskdef 的一种方法是将其插入到 for 循环之前:

<target>
    <taskdef resource="net/sf/antcontrib/antlib.xml"
             classpathref="maven.plugin.classpath" />
    <for param="extension">
    ...

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:

Problem: failed to create task or type for

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

<target>
    <taskdef resource="net/sf/antcontrib/antlib.xml"
             classpathref="maven.plugin.classpath" />
    <for param="extension">
    ...
脸赞 2024-10-13 22:23:40

在浪费了 2 个小时并阅读了太多答案之后,这就是我需要检查的

http://www.thinkplexx.com/learn/howto/maven2/plugins/could-not-load-definitions -from-resource-antlib-xml-understanding-the-problem-and-fix-worklow

我使用它打印了所有 Maven 类路径

<property name="compile_classpath" refid="maven.compile.classpath"/>
<property name="runtime_classpath" refid="maven.runtime.classpath"/>
<property name="test_classpath" refid="maven.test.classpath"/>
<property name="plugin_classpath" refid="maven.plugin.classpath"/>
<echo message="compile classpath: ${compile_classpath}"/>
<echo message="runtime classpath: ${runtime_classpath}"/>
<echo message="test classpath:    ${test_classpath}"/>
<echo message="plugin classpath:  ${plugin_classpath}"/>

,并检查了哪个类路径包含 antrib jar 文件。所以我将 classpathhrefmaven.plugin.classpath 更改为 maven.runtime.classpath
。所以我的 taskdef

<taskdef resource="net/sf/antcontrib/antcontrib.properties" classpathref="maven.runtime.classpath" />

和依赖项

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

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

<property name="compile_classpath" refid="maven.compile.classpath"/>
<property name="runtime_classpath" refid="maven.runtime.classpath"/>
<property name="test_classpath" refid="maven.test.classpath"/>
<property name="plugin_classpath" refid="maven.plugin.classpath"/>
<echo message="compile classpath: ${compile_classpath}"/>
<echo message="runtime classpath: ${runtime_classpath}"/>
<echo message="test classpath:    ${test_classpath}"/>
<echo message="plugin classpath:  ${plugin_classpath}"/>

and checked which classpath contains antrib jar file. So I changed classpathhref to maven.runtime.classpath from maven.plugin.classpath
. So my taskdef is

<taskdef resource="net/sf/antcontrib/antcontrib.properties" classpathref="maven.runtime.classpath" />

and the 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>
み格子的夏天 2024-10-13 22:23:40

我也在这个问题上浪费了几个小时,因为找不到 antcontrib for 任务。

最后,我发现for任务不是在antcontrib.properties中定义的,而是在antlib.xml中定义的!

antcontrib.properties 是 ant 1.6 之前的处理方式 - 现代方式是使用 antlib.xml

所以,这是一个 ma​​ven 3.5ant 1.8 的工作示例:

<plugin>
    <artifactId>maven-antrun-plugin</artifactId>
    <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>
    </dependencies>

    <execution>
        <id>deploy_to_distrib_folder</id>
        <phase>package</phase>
        <configuration>

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

                <macrodef name="deploy_extra_dir">
                    <attribute name="dir" />
                    <sequential>
                        <basename property="basename" file="@{dir}" />
                        <sync todir="${outputDir}/${basename}">
                            <fileset dir="@{dir}" />
                        </sync>
                        <var name="basename" unset="true" />
                    </sequential>
                </macrodef>

                <for param="dir">
                    <path>
                        <dirset dir="${project.build.directory}/maven-shared-archive-resources" includes="*" />
                    </path>
                    <sequential>
                        <deploy_extra_dir dir="@{dir}" />
                    </sequential>
                </for>

            </target>
        </configuration>
        <goals>
            <goal>run</goal>
        </goals>
    </execution>
</plugin>

希望这会有所帮助!

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 in antcontrib.properties, but in antlib.xml!

antcontrib.properties is a pre ant 1.6 way of doing things – the modern way is to use antlib.xml.

So, this is a maven 3.5, ant 1.8, working example:

<plugin>
    <artifactId>maven-antrun-plugin</artifactId>
    <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>
    </dependencies>

    <execution>
        <id>deploy_to_distrib_folder</id>
        <phase>package</phase>
        <configuration>

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

                <macrodef name="deploy_extra_dir">
                    <attribute name="dir" />
                    <sequential>
                        <basename property="basename" file="@{dir}" />
                        <sync todir="${outputDir}/${basename}">
                            <fileset dir="@{dir}" />
                        </sync>
                        <var name="basename" unset="true" />
                    </sequential>
                </macrodef>

                <for param="dir">
                    <path>
                        <dirset dir="${project.build.directory}/maven-shared-archive-resources" includes="*" />
                    </path>
                    <sequential>
                        <deploy_extra_dir dir="@{dir}" />
                    </sequential>
                </for>

            </target>
        </configuration>
        <goals>
            <goal>run</goal>
        </goals>
    </execution>
</plugin>

Hope this helps!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文