War 文件生成之前的 Maven 复制文件夹

Maven Copy Folder Before War File Generation

我有两个 Git 存储库。一个仓库是java服务(maven web项目),另一个仓库由UI{HTML、JS、CSS}(非maven)组成,当时是java 服务存储库构建 我想将最新的 UI(master)包含到 war 文件中。我试过 maven-resources-plugin

<build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.2</version>
                <configuration>
                    <source>1.7</source>
                    <target>1.8</target>
                </configuration>
            </plugin>
            <plugin>
                <artifactId>maven-resources-plugin</artifactId>
                <version>2.7</version>
                <executions>
                    <execution>
                        <id>copy-resources</id>
                        <!-- here the phase you need -->
                        <phase>install</phase>
                        <goals>
                            <goal>copy-resources</goal>
                        </goals>
                        <configuration>
                            <outputDirectory>${basedir}/target/</outputDirectory>
                            <resources>
                                <resource>
                                    <directory>/home/srinivas/AAA/bb/</directory>
                                </resource>
                            </resources>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

mvn install

它将资源复制到目标文件夹,但没有将它们放在 war 文件中

乍一看,变化:

<phase>install</phase>

<phase>prepare-package</phase>

您在执行中使用了错误的阶段,因为 package 阶段实际上是创建 war 的阶段,因此您需要在较早的阶段执行,例如prepare-package.

您一定要阅读 Introduction to the Build Lifecycle 以了解清楚。

此外,您不应该习惯于通过 maven-resources-plugin 从文件系统中拉取资源。由于其他开发人员将无法重现您的构建,因此通常不赞成这种做法。

使用存储库管理器来存储您的依赖项是解决此问题的方法。阅读 Why do I need a Repository Manager? 开始。