【问题标题】:Copying file from one project to another in maven在maven中将文件从一个项目复制到另一个项目
【发布时间】:2012-01-13 06:22:57
【问题描述】:

我正在开发一个多模块项目。我们在其他几个模块中使用来自一个模块的 appCtx.xml。

当前的问题是它们并不总是彼此同步。

当有人修改文件并构建项目时会发生这种情况,这样做的人可能会忘记复制到另一个模块并导致问题。

如何将 src/main/resources 中的 appCtx.xml 从项目 A 复制到项目 B 中的 src/main/resources?

【问题讨论】:

标签: java maven maven-2


【解决方案1】:

您可以使用maven resources plugin: copy-resources 执行此操作,例如:

<plugin>
    <artifactId>maven-resources-plugin</artifactId>
    <executions>
        <execution>
            <id>copy-appCtx</id>
            <phase>generate-resources</phase>
            <goals>
                <goal>copy-resources</goal>
            </goals>
            <configuration>
                <outputDirectory>${project.build.directory}/src/blahhere</outputDirectory>
                <overwrite>true</overwrite>
                <resources>
                    <resource>
                        <directory>../other_project/src/blah/blah</directory>
                        <includes>
                            <include>appCtx.xml</include>
                        </includes>
                    </resource>
                </resources>
            </configuration>
        </execution>
    </executions>
</plugin>

这会从一个项目(位于同一源代码树上)复制一个文件,作为生成资源阶段的一部分。您可以根据自己的需要进行调整。

如果项目不是一次全部构建,则从一个项目复制到另一个项目可能会导致构建不稳定,但上述方法适用于始终一起构建的项目。

【讨论】:

  • 路径../other_project/src/blah/blah 假设两个项目当前都存储在我的磁盘上,我是否正确?如果源项目没有在本地克隆,但资源应该从工件中的快照中获取,我该怎么做?
猜你喜欢
  • 2018-03-24
  • 1970-01-01
  • 1970-01-01
  • 2013-01-04
  • 1970-01-01
  • 2021-11-22
  • 1970-01-01
  • 2020-10-10
  • 1970-01-01
相关资源
最近更新 更多