【问题标题】:Copy resource files from submodule into main module in maven将资源文件从子模块复制到maven中的主模块
【发布时间】:2018-06-05 12:55:15
【问题描述】:

在我的 java 应用程序中,我只是想知道是否可以将 src/main/resources 下的资源文件从 maven 子模块复制或仅使用到主 maven 模块(它具有子模块作为依赖项) src/ main/resources 文件夹,所以我不需要手动将所有资源文件再次复制到我的工作区中。

【问题讨论】:

    标签: java maven resources


    【解决方案1】:

    您可以使用 maven 依赖插件来做到这一点。

    这是一个配置,您可以将其包含在 build > plugins 部分的主模块 pom.xml 中。

    <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-dependency-plugin</artifactId>
                <version>3.1.1</version>
                <executions>
                    <execution>
                        <id>unpack</id>
                        <phase>initialize</phase>
                        <goals>
                            <goal>unpack</goal>
                        </goals>
                        <configuration>
                            <artifactItems>
                                <artifactItem>
                                    <groupId>hepl.cecotepe.epick</groupId>
                                    <artifactId>wsdl</artifactId>
                                    <version>${wsdl.version}</version>
                                    <type>jar</type>
                                </artifactItem>
                            </artifactItems>
                            <overWrite>true</overWrite>
                            <outputDirectory>${basedir}/src/main/resources/webservices</outputDirectory>
                            <includes>**/*.wsdl, **/*.xsd</includes>
                            <excludes>**/META*/**, **/Documentation/**</excludes>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
    

    artifactItem 是您要将文件复制到模块中的模块。在这种情况下,您将使用子模块 groupId、artifactId 和版本填充 artifactItem 字段。

    插件将获取所有文件夹(包括目标、src 和子文件夹)中的所有 .wsdl 和 .xsd 文件,除了 Documentation 和 META* 文件夹(和子文件夹)。每次都会将文件复制到主模块 /resources/webservices 文件夹中。

    要使整个工作正常,您需要将子模块打包为 jar(在子模块 pom.xml 中包含 jar)并使用 mvn install 将其安装到本地 maven 存储库中。之后,您可以使用 mvn initialize

    复制主模块中的文件

    注意:初始化阶段包含在默认生命周期中,是执行的第一个阶段。当您使用默认生命周期时,maven 会做的第一件事是将文件从子模块复制到主模块。

    【讨论】:

      猜你喜欢
      • 2016-01-29
      • 2011-11-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-06-09
      • 2012-01-07
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多