【问题标题】:Maven antrun with sequential ant-contrib fails to run具有顺序 ant-contrib 的 Maven antrun 无法运行
【发布时间】:2010-12-06 15:56:51
【问题描述】:

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

【问题讨论】:

    标签: ant maven-2 maven-3 maven-antrun-plugin


    【解决方案1】:

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

    我使用 maven3 和上面描述的其余部分,但我必须使用 maven.dependency.classpath 而不是maven.plugin.classpath!否则 maven 将找不到 contrib 任务。希望这对任何人都有帮助。

    【讨论】:

      【解决方案2】:

      您似乎缺少declare the ant-contrib tasks 所需的taskdef,以便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">
          ...
      

      【讨论】:

      • 谢谢,这对我很有用。我也试过了,但使用了错误的类路径引用。
      【解决方案3】:

      浪费了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>
      

      【讨论】:

        【解决方案4】:

        我在这个上也浪费了几个小时,因为找不到 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>
        

        希望这会有所帮助!

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2011-06-06
          • 2019-09-06
          • 1970-01-01
          • 1970-01-01
          • 2012-06-30
          • 2017-08-06
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多