解包WAR未解包

时间:2017-02-28 18:13:55

标签: maven maven-3 maven-dependency-plugin spring-boot-maven-plugin

我正在努力实现与here发布的问题相同的目标,即将war依赖集合到一个可部署的zip中,在最终的zip中包含war和一些解压缩的* .yml文件。我已经将war文件正确地组装到zip中,但是我无法获得maven-dependency-plugin来解压缩战争中的* .yml文件以进行重新打包。

为清楚起见,这就是我所拥有的:

  • 项目1
    • 姓名:myapp-war
    • 包装:战争
  • 项目2
    • 姓名:myapp-deploy
    • 包装:pom
    • 依赖:myapp-war:war
    • 所需输出:myapp.zip包括:
      • 仓/ myapp.war
      • conf / application - *。yml

这是我的插件声明的样子:

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-dependency-plugin</artifactId>
            <version>3.0.0</version>
            <executions>
                <execution>
                    <id>unpack</id>
                    <phase>prepare-package</phase>
                    <goals>
                        <goal>unpack</goal>
                    </goals>
                    <configuration>
                        <artifactItems>
                            <artifactItem>
                                <groupId>myapp</groupId>
                                <artifactId>myapp-war</artifactId>
                                <type>war</type>
                                <outputDirectory>${project.build.directory}/unpack</outputDirectory>
                                <includes>**/*.yml</includes>
                            </artifactItem>
                        </artifactItems>
                    </configuration>
                </execution>
            </executions>
        </plugin>

我还尝试过一种变体,我在<outputDirectory>下面宣布<includes><configuration>[INFO] Configured Artifact: myapp:myapp-war:?:war [INFO] Unpacking /build/myapp-war/target/myapp-war-0.0.1-SNAPSHOT.war to /build/myapp-deploy/target/unpack with includes "**/*.yml" and excludes "" [DEBUG] Found unArchiver by type: org.codehaus.plexus.archiver.zip.ZipUnArchiver$__sisu2@692a65b1 [DEBUG] Expanding: /build/myapp-war/target/myapp-war-0.0.1-SNAPSHOT.war into /build/myapp-deploy/target/unpack [DEBUG] expand complete 允许这样做。

在任何一种情况下,我得到一个空的myapp-deploy / target / unpack文件夹,以及maven输出中的[INFO]和[DEBUG]消息说明:

{{1}}

maven似乎理解了我的指示,但似乎并没有像它声称的那样拆开包装。知道我做错了吗?

1 个答案:

答案 0 :(得分:1)

创建* .war依赖项显然存在问题。它首先使用maven-war-plugin:war创建,然后使用spring-boot-maven-plugin:repackage重新打包。从命令行解压缩成功,但会产生警告:

$ unzip myapp-war-0.0.1-SNAPSHOT.war
Archive:  myapp-war-0.0.1-SNAPSHOT.war
warning [myapp-war-0.0.1-SNAPSHOT.war]:  7318 extra bytes at beginning or within zipfile

如果我将spring-boot-maven-plugin:repackage配置为禁用executable * nix启动脚本前置战争,maven-dependency-plugin:unpack按预期工作:

<plugin>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-maven-plugin</artifactId>
    <executions>
        <execution>
            <goals>
                <goal>repackage</goal>
            </goals>
        </execution>
    </executions>
    <configuration>
        <executable>false</executable>
    </configuration>
</plugin>