北方的郎 2016年01月27日 代码异常 浏览(878)

maven-assembly-plugin报异常:Error creating assembly archive statics: You must set at least one file

maven-assembly-plugin报如下异常:

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-assembly-plugin:2.4.1:single (make-assembly) on project assemblyDemo: Failed to create assembly: Error creating assembly archive statics: You must set at least one file. -> [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.


其中pom文件配置如下:


<!-- 静态内容另打zip包配置 -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-assembly-plugin</artifactId>
                <version>2.4.1</version>
                <executions>
                    <execution>
                        <id>make-assembly</id>
                        <phase>package</phase>
                        <goals>
                            <goal>single</goal>
                        </goals>
                        <configuration>
                            <finalName>
                                ${project.artifactId}-${project.version}
                            </finalName>
                            <descriptors>
                                <descriptor>
                                    src/assemble/statics-zip.xml
                                </descriptor>
                            </descriptors>
                        </configuration>
                    </execution>
                </executions>
            </plugin>


statics-zip.xml的配置文件如下:


<?xml version="1.0" encoding="UTF-8"?>
<assembly
    xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0 http://maven.apache.org/xsd/assembly-1.1.0.xsd">
    <id>statics</id>
    <formats>
        <format>zip</format>
    </formats>
    <includeBaseDirectory>false</includeBaseDirectory>
    <fileSets>
        <fileSet>
            <directory>${basedir}/src/main/webapp/statics-gen</directory>
            <outputDirectory>/</outputDirectory>
        </fileSet>
    </fileSets>
</assembly>


最佳回答
请注意statics-zip.xml中如下代码:
<directory>${basedir}/src/main/webapp/statics-gen</directory>
则表明项目/src/main/webapp/目录下必须存在statics-gen文件夹,如果不存在则会报异常:You must set at least one file
原因是在${basedir}/src/main/webapp/目录下找不到指定文件夹:statics-gen。
笔者发现如果文件夹指定正确,但是使用maven命令:mvn assembly:assembly 仍然会报如下错误:
Error reading assemblies: No assembly descriptors found.
但是实际上zip文件包已成功生成。
于是更换命令:mvn clean package  执行成功,生成war包和zip静态压缩文件。
感谢阿鲁巴的贡献!