java - maven-remote-resources-plugin 不复制文件,仅复制文件夹结构

标签 java maven maven-plugin

我有一个 Maven 项目,其中一个模块是一个 Java Web 应用程序(A 模块),另一个模块(B 模块)也是一个 Java Web 应用程序,它使用 A 模块中的类及其资源。创建一个 jar 并将其安装在 Maven 存储库中,编译 B 模块没有问题,但我的问题是将资源从 A 复制到 B。

我正在尝试从 A 模块复制 jsp 和其他文件。按照文档和一些博客,我设法获取了 target\classes\META-INF\maven\remote-resources.xml,但是当我尝试在 B 模块中复制这些资源时,我只得到了文件夹结构,但内部有任何文件。

模块 pom

<profile>
    <id>validator</id>
    <properties>
        <packaging.type>jar</packaging.type>
    </properties>
    <build>
        <plugins>
            <plugin>
                <artifactId>maven-remote-resources-plugin</artifactId>
                <version>1.4</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>bundle</goal>
                        </goals>
                        <configuration>
                            <resourcesDirectory>${project.basedir}/src/main/webapp</resourcesDirectory>
                            <excludes>
                                <exclude>**/WEB-INF/**</exclude>
                                <exclude>**/META-INF/**</exclude>
                            </excludes>
                            <includes>
                                <include>**/*.*</include>
                            </includes>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</profile>

B模块pom

<profile>
    <id>embedded</id>
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-remote-resources-plugin</artifactId>
                <version>1.4</version>
                <configuration>
                    <resourceBundles>
                        <resourceBundle>my.group:my.artifact:${my.version}</resourceBundle>
                    </resourceBundles>
                </configuration>
                <executions>
                    <execution>
                        <goals>
                            <goal>process</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
        <resources>
            <resource>
                <directory>${project.basedir}/src/main/resources</directory>
            </resource>
            <resource>
                <directory>${project.basedir}/src/main/config/embedded</directory>
            </resource>
        </resources>
    </build>
</profile>

在输出中,我没有收到任何错误,但 target\maven-shared-archive-resources\ 中没有文件,只有模块 A 中的文件夹结构。

知道我做错了什么吗?

最佳答案

好的,我找到了解决方案。 看起来远程 maven-remote-resources-plugin 仅适用于 src/main/resources 下的资源,所以在我的例子中,技巧是通过资源将/webapp/* 复制到该文件夹​​,并在复制资源后执行插件我有指定<phase>process-resources</phase>在插件中,因为否则它会在资源就位之前执行。 这是配置文件的代码

<profile>
            <id>share-resources</id>
            <properties>
                <packaging.type>jar</packaging.type>
            </properties>
            <build>
                <resources>
                    <resource>
                        <directory>${project.basedir}/src/main/resources</directory>
                    </resource>
                    <resource>
                        <directory>${project.basedir}/src/main/config/embedded</directory>
                    </resource>
                    <!-- This is the one for webapp -->
                    <resource>
                        <directory>${project.basedir}/src/main/webapp</directory>
                        <targetPath>${project.build.outputDirectory}/shared-resources</targetPath>
                        <excludes>
                            <exclude>**/WEB-INF/**</exclude>
                            <exclude>**/META-INF/**</exclude>
                        </excludes>
                    </resource>
                </resources>
                <plugins>
                    <plugin>
                        <artifactId>maven-remote-resources-plugin</artifactId>
                        <version>1.5</version>
                        <executions>
                            <execution>
                                <phase>process-resources</phase>
                                <goals>
                                    <goal>bundle</goal>
                                </goals>
                                <configuration>
                                    <resourcesDirectory>${project.build.outputDirectory}</resourcesDirectory>
                                    <excludes>
                                        <exclude>**/WEB-INF/**</exclude>
                                        <exclude>**/META-INF/**</exclude>
                                    </excludes>
                                    <includes>
                                        <include>**/shared-resources/**/*.*</include>
                                    </includes>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>

要检索模块 B 中的资源,请按照文档中的说明进行操作

关于java - maven-remote-resources-plugin 不复制文件,仅复制文件夹结构,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27905674/

相关文章:

java - 如何使用命令行为Java应用程序生成冒烟测试用例

java - Maven 3 : Failed to execute goal org. apache.maven.plugins :maven-archetype-plugin:2. 2:生成

android - 用于 Android 开发的 Maven 集成

java - 将 main 中创建的实例传递给 Java 中的类

java - Netbeans 导致我的 Logo 颜色反转?

java - 比较器和 BST

java - 如何使用 jar 运行 cucumber ?

java - Java 中的 AWS DynamoDB 和 MapReduce

java - org.mortbay.http 包不存在。如何在 pom.xml 中为此添加依赖项

Maven Invoker 插件与 Maven Failsafe 插件 : Which to use for integration-test?