7

サブフォルダー内のファイルを拡張子に分解する特別なルーチンがあり、これがコピーされ、単一の拡張子ファイルに jar されます。この特別なアプローチでは、 を使用したかったの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
4

4 に答える 4

10

したがって、私は少なくとも1時間無駄にして、以下の小さなヒントのエラーを見つけました...

上記のようにmaven3と残りを使用しますが、maven.dependency.classpath 代わりに使用する必要がありmaven.plugin.classpathます。そうしないと、Mavenはcontribタスクを見つけられません。これが誰かに役立つことを願っています。

于 2012-11-26T16:41:26.430 に答える
9

ant-contrib tasksを宣言するために必要なtaskdefが欠落しているように見えるため、Ant はそれらについて認識できるため、エラー メッセージの次の部分が表示されます。

Problem: failed to create task or type for

'for'(失敗したタスクが引用されていれば、おそらくもう少し明確になるでしょう。)

fortaskdef を追加する 1 つの方法は、ループの直前に挿入することです。

<target>
    <taskdef resource="net/sf/antcontrib/antlib.xml"
             classpathref="maven.plugin.classpath" />
    <for param="extension">
    ...
于 2010-12-07T01:00:13.197 に答える
0

antcontribforタスクが見つからなかったため、私もこれに数時間を費やしました。

for最後に、そのタスクが ではなく で定義されていることがわかりましantcontrib.propertiesantlib.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>

お役に立てれば!

于 2018-11-09T13:58:48.350 に答える