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

时间:2015-01-12 15:44:27

标签: java maven maven-plugin

我有一个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中。

知道我做错了吗?

1 个答案:

答案 0 :(得分:1)

好的,我找到了解决方案。 看起来像远程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中的资源,只需按照文档

进行操作
相关问题