【问题标题】:A zip file cannot include itself - Maven-assembly pluginzip 文件不能包含自身 - Maven-assembly 插件
【发布时间】:2014-03-14 05:36:46
【问题描述】:

我正在使用 maven 程序集插件构建一个项目。但是该过程失败并出现以下错误,(这里我将错误粘贴在jenkins中。我也检查了没有jenkins。)

[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 2:29.792s
[INFO] Finished at: Fri Mar 14 10:26:58 IST 2014
[INFO] Final Memory: 26M/75M
[INFO] ------------------------------------------------------------------------
Waiting for Jenkins to finish collecting data
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-assembly-plugin:2.2-beta-5:assembly (default) on project ExecutionBot: Failed to create assembly: Error creating     assembly archive jar-with-dependencies: A zip file cannot include itself -> [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

pom.xml 中的配置

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-assembly-plugin</artifactId>
    <executions>
  <execution>
     <goals>
       <goal>assembly</goal>
     </goals>
     <phase>package</phase>
     <configuration>
       <descriptorRefs>
         <descriptorRef>jar-with-dependencies</descriptorRef>
      </descriptorRefs>
      <archive>
        <manifest>
          <mainClass>com.starter.MyListner</mainClass>
        </manifest>
      </archive>
     </configuration>
     </execution>
    </executions>
</plugin>

【问题讨论】:

  • 也许您正在尝试将创建的 zip 文件保存在文件夹中,您在该文件夹中迭代文件并添加到 zip。
  • 是的,这就是发生了什么。知道如何通过配置解决它
  • 请更新到最新版本的 maven-assembly-plugin (2.4) 而不是真正的旧版本。此外,请出示您的完整 pom 文件。
  • 谢谢兄弟。是的,概率与版本有关。无论如何都解决了。我把它放在下面

标签: maven maven-plugin maven-assembly-plugin


【解决方案1】:

在我的情况下,问题在于 maven 程序集插件的版本。默认情况下,它使用 2.2 版并且存在一些问题(直到今天,他们可能会在将来修复它)。更好地使用 2.1。所以定制我的代码如下。现在它工作正常

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-assembly-plugin</artifactId>
    <version>2.1</version>
    <executions>
         <execution>
         <goals>
            <goal>assembly</goal>
         </goals>
         <phase>package</phase>
         <configuration>
         <descriptorRefs>
             <descriptorRef>jar-with-dependencies</descriptorRef>
         </descriptorRefs>
         <archive>
        <manifest>
          <mainClass>com.starter.MyListner</mainClass>
        </manifest>
       </archive>
      </configuration>
   </execution>
   </executions>
</plugin> 

【讨论】:

【解决方案2】:

尝试在您的配置中添加排除

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-assembly-plugin</artifactId>
    <executions>
  <execution>
     <goals>
       <goal>assembly</goal>
     </goals>
     <phase>package</phase>
     <configuration>
       <descriptorRefs>
         <descriptorRef>jar-with-dependencies</descriptorRef>
      </descriptorRefs>
      <archive>
        <manifest>
          <mainClass>com.starter.MyListner</mainClass>
        </manifest>
      </archive>
                <excludes>
                    <exclude>**/*.zip</exclude>
                </excludes>
     </configuration>
     </execution>
    </executions>
</plugin>

【讨论】:

  • 谢谢兄弟。我解决了。我将在下面展示它。这也可能是一个解决方案。 :) (y)
【解决方案3】:

在我的例子中,我有一个空的 includes 标签。

<assembly>
    <id>assembly</id>
    <formats>
        <format>zip</format>
    </formats>
    <fileSets>
        <fileSet>
            <outputDirectory>lib</outputDirectory>
            <includes>
            </includes>
        </fileSet>
    </fileSets>
</assembly>

【讨论】:

    【解决方案4】:

    在这里,您使用了带有 jar-with-dependencies 的程序集插件。这将创建一个 zip 文件,例如 xyz-jar-with-dependencies.zip。 该错误清楚地表明您不能在 xyz-jar-with-dependencies.zip 中包含任何 *.zip。 因此,如果您 &lt;excludes&gt; &lt;exclude&gt;**/*.zip&lt;/exclude&gt; &lt;/excludes&gt; 形成您的程序集配置或使用程序集描述符,则可以修复此错误。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-12-29
      • 2016-01-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-12-20
      相关资源
      最近更新 更多