当前位置: 代码迷 >> 综合 >> maven 报错 Failed to create assembly: archive cannot be empty
  详细解决方案

maven 报错 Failed to create assembly: archive cannot be empty

热度:10   发布时间:2023-11-17 21:36:03.0

背景:

pom.xml 里面 plugin 的配置如下:

                <plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-assembly-plugin</artifactId><version>3.1.1</version><configuration><finalName>${project.artifactId}</finalName><appendAssemblyId>true</appendAssemblyId><descriptors><descriptor>src/main/assembly/client-jar.xml</descriptor></descriptors></configuration><executions><execution><id>make-assembly</id><phase>package</phase><goals><goal>single</goal></goals></execution></executions></plugin>

src/main/assembly/client-jar.xml 配置如下:

<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2 http://maven.apache.org/xsd/assembly-1.1.2.xsd"><id>client</id><formats><format>jar</format></formats><includeBaseDirectory>false</includeBaseDirectory><fileSets><fileSet><directory>target/classes</directory><includes>  <include>**/embedclient/**</include><include>**/model/**</include>  </includes> <outputDirectory>${file.separator}</outputDirectory></fileSet></fileSets>
</assembly>

执行命令 mvn assembly:single 的时候出现下面错误:

[INFO] Scanning for projects...
[WARNING] Failed to build parent project for xxx.xxxx.xxx:xxx:war:0.0.1
[INFO]
[INFO] ------------------< xxx.xxxx.xxx:xxx >-------------------
[INFO] Building xxx Maven Webapp 0.0.1-SNAPSHOT
[INFO] --------------------------------[ war ]---------------------------------
[INFO]
[INFO] --- maven-assembly-plugin:3.1.1:single (default-cli) @ xxx ---
[INFO] Reading assembly descriptor: src/main/assembly/client-jar.xml
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  1.430 s
[INFO] Finished at: 2021-06-01T14:45:20+08:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-assembly-plugin:3.1.1:single (default-cli) on project xxx: Failed to creat
e assembly: Error creating assembly archive client: archive cannot be empty -> [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

在网上收了半天没有发现有 archive cannot be empty 相关错误, 后面想着 存档不能为空 是不是没有相关 class 文件的原因,先执行一下 clean 和 compile,再执行 assembly 就好了,具体命令:

mvn clean
mvn compile
mvn assembly:single
  相关解决方案