Frage

Wir haben eine spezielle Routine-Dateien in einem Unterordner in Erweiterungen zu explodieren, die kopiert werden und jared in einzelne Erweiterungsdateien. Für diesen speziellen Ansatz wollte ich für die sequentielle Iteration und Glas Verpackung durch die dirset die maven-antrun-plugin, verwenden, müssen wir die Bibliothek ant-contrib.

Die kommende Plugin-Konfiguration nicht mit einem Fehler. Was habe ich falsch konfiguriert? Danke.

Plugin-Konfiguration

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

Fehler

[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
War es hilfreich?

Lösung

Es sieht aus wie Sie die taskdef sind vermisst , die auf erklärt die ant-contrib Aufgaben , so dass Ant über sie weiß, damit die Fehlermeldung diesen Teil:

Problem: failed to create task or type for

(Es wäre vielleicht ein wenig klarer, wenn die ausgefallene Aufgabe - 'for' -. Zitiert wurde)

Eine Möglichkeit, die taskdef hinzuzufügen, ist es unmittelbar vor der for Schleife einzufügen:

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

Andere Tipps

Deshalb ich mindestens eine Stunde verschwendet den Fehler ein kleiner Hinweis unten ...

finden

Ich benutze maven3 und den Rest, wie oben beschrieben, aber ich habe maven.dependency.classpath verwenden statt maven.plugin.classpath! Ansonsten maven die contrib Aufgaben nicht finden. Hoffe, das hilft niemandem.

Nach 2 Stunden zu verschwenden und zu vielen Antworten zu lesen, ist es das, was ich überprüfen muß

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

Ich druckte alle Maven CLASSPATHs mit diesen

<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}"/>

und überprüft die Classpath antrib JAR-Datei enthält. Also änderte ich classpathhref zu maven.runtime.classpath von maven.plugin.classpath . Also mein taskdef ist

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

und die Abhängigkeiten

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

Auch ich mehrere Stunden auf diesem verschwendet, weil antcontrib for Aufgabe konnte nicht gefunden werden.

Schließlich fand ich, dass for Aufgabe heraus in nicht in antcontrib.properties definiert, aber in antlib.xml!

antcontrib.properties ist ein Pre ant 1.6 Art und Weise, Dinge zu tun -. Die moderne Art und Weise ist die Verwendung antlib.xml

Also, das ist ein maven 3.5 , ant 1.8 , Arbeitsbeispiel:

<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, das hilft!

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top