繁体   English   中英

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

[英]maven-remote-resources-plugin doesn't copy files, only folder structure

我有一个Maven项目,其模块是一个Java Web应用程序(一个模块),另一个模块(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中的资源,就像在文档中一样

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM