【问题标题】:Extract all classes under in "model" packages to a separate Maven module将“模型”包中的所有类提取到单独的 Maven 模块
【发布时间】:2014-06-26 03:56:03
【问题描述】:

我有一个 maven 模块,其 src 目录如下所示:

src/
  main/
   foo/
     model/
       ModelA.java
   bar/
     model/
       ModelB.java

将“模型”包中的所有类提取到单独的 Maven 模块中的最简单方法是什么? (即我想将 ModelA 和 ModelB 移动到单独的模块中)

【问题讨论】:

    标签: java maven


    【解决方案1】:

    您可以在 pom.xml 中定义一个复制资源插件:

    <plugin>
    <artifactId>maven-resources-plugin</artifactId>
    <version>2.4.3</version>
    <executions>
        <execution>
            <id>copy-models</id>
            <phase>validate</phase>
            <goals>
                <goal>copy-resources</goal>
            </goals>
            <configuration>
                <outputDirectory>{code_base}/new-module/src/main/foo/model> <!-- location where models need to be copied -->
                <overWrite>true</overWrite>
                <resources>
                    <resource>
                        <directory>src/main/*/model/*.java</directory>
                        <filtering>true</filtering>
                    </resource>
                </resources>
            </configuration>
        </execution>
    </executions>
    </plugin>
    

    【讨论】:

    • 酷!在 outputDirectory 中复制时,有没有办法保持结构相同?在您的示例中,所有内容都将在 main/foo/model 包中。但是如果我在输出目录中也需要 foo/model/ bar/model/ 包怎么办?
    • 我认为你可以尝试在 outputDirectory 中使用 src/main/。 AFAIK,可以通过这种方式复制源中的整个文件夹结构。
    猜你喜欢
    • 2020-08-16
    • 1970-01-01
    • 2019-02-18
    • 2021-05-30
    • 2013-06-23
    • 2011-08-27
    • 1970-01-01
    • 2012-01-07
    • 2018-11-28
    相关资源
    最近更新 更多