Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/ant/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
带有顺序ant contrib的Maven antrun无法运行_Ant_Maven 2_Maven 3_Maven Antrun Plugin - Fatal编程技术网

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

带有顺序ant contrib的Maven antrun无法运行,ant,maven-2,maven-3,maven-antrun-plugin,Ant,Maven 2,Maven 3,Maven Antrun Plugin,我们有一个特殊的例程将子文件夹中的文件分解为扩展名,这些扩展名将被复制并放入单个扩展名文件中。对于这种特殊的方法,我想使用maven-antrun插件,对于通过dirset的顺序迭代和jar打包,我们需要库ant-contrib 即将到来的插件配置失败并出现错误。我误解了什么?多谢各位 插件配置 <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-an

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

org.apache.maven.plugins
maven antrun插件
1.6
验证
跑
抗辩人
抗辩人
1.0b3
蚂蚁
蚂蚁
org.apache.ant
蚂蚁结
1.8.1
错误

[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
[ERROR]无法在项目扩展平台上执行目标org.apache.maven.plugins:maven-antrun-plugin:1.6:run(默认值):发生Ant BuildException:问题:无法为创建任务或类型
[错误]原因:名称未定义。
[错误]操作:检查拼写。
[错误]操作:检查是否已声明任何自定义任务/类型。
[错误]操作:检查是否发生了任何/声明。
[错误]->[帮助1]
[错误]
[错误]要查看错误的完整堆栈跟踪,请使用-e开关重新运行Maven。
[错误]使用-X开关重新运行Maven以启用完整调试日志记录。
[错误]
[错误]有关错误和可能的解决方案的更多信息,请阅读以下文章:
[错误][帮助1]http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException

看起来您缺少了所需的,以便Ant知道它们,因此错误消息的这一部分:

Problem: failed to create task or type for
(如果引用失败的任务--'for',可能会更清楚一些。)

添加taskdef的一种方法是在循环的
之前插入它:

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

...

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

如上所述,我使用maven3和其他版本,但我必须使用
maven.dependency.classpath

而不是
maven.plugin.classpath
!否则maven将找不到contrib任务。希望这对任何人都有帮助。

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

我用这个打印了所有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}"/>
以及依赖关系

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

抗辩人
抗辩人
1.0b3
蚂蚁
蚂蚁
org.apache.ant
蚂蚁结
1.8.1

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

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

antcontrib.properties
是ant 1.6之前的一种处理方法–现代的方法是使用
antlib.xml

因此,这是一个maven 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>

maven antrun插件
抗辩人
抗辩人
1.0b3
蚂蚁
蚂蚁
将\u部署到\u发行版\u文件夹
包裹
跑


希望这有帮助

谢谢,这对我很有效。我也试过了,但使用了错误的类路径引用。
<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>