2010-12-06 41 views
6

我們有一個特殊的例程,用於將子文件夾中的文件分解爲擴展名,這些擴展名將被複制並加密到單個擴展文件中。對於這種特殊的方法,我想使用maven-antrun-plugin,通過dirset進行順序迭代和jar包裝,我們需要庫ant-contrib。Maven antrun with sequential ant-contrib could not run

即將發生的插件配置失敗並顯示錯誤。我錯了什麼配置?謝謝。

插件配置

<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 

回答

9

它看起來像你缺少真實需要declare the ant-contrib taskstaskdef,讓螞蟻知道他們而言,因此這部分錯誤消息:

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"> 
    ... 
+0

謝謝你,這對我來說真是棒極了。我也試過這個,但使用了錯誤的類路徑引用。 – codevour 2010-12-07 08:59:55

10

因此,我浪費了至少一個小時才找到下面的錯誤一個小提示...

我用maven3並且如上所述休息,但我必須使用maven.dependency.classpath 代替maven.plugin.classpath !否則,maven將無法找到contrib任務。希望這可以幫助任何人。

0

浪費2小時,讀了太多的答案後,這是我需要檢查

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

我用這個

<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文件。所以我從maven.plugin.classpath 更改classpathhrefmaven.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>