在maven中将文件从一个项目复制到另一个项目 [英] Copying file from one project to another in maven

查看:1394
本文介绍了在maven中将文件从一个项目复制到另一个项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm working on a multi-module project. We're using the appCtx.xml from one module in few other modules.

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

Current issue is that they're not always in sync with each other.

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

It happens when someone modifies the file and the project builds, the person doing that can forget to copy to another module and it causes issues.

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

How do I copy appCtx.xml inside src/main/resources from project A to src/main/resources in project B?

推荐答案

您可以使用 maven resources插件执行此操作: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>

这是从一个项目(共同位于同一源树上)复制文件,作为生成的一部分 - 资源阶段。你可以根据自己的需要调整它。

This copies a file from one project (colocated on the same source tree) as part of the generate-resources phase. You can adapt this to your needs.

如果项目不是一次全部构建,那么从一个项目复制到另一个项目可能会导致不稳定的构建,但上面的工作会有效对于总是一起建造的项目。

This copying from one project to another may cause unstable builds if the projects aren't all built at once, but the above will work for projects which are always built together.

这篇关于在maven中将文件从一个项目复制到另一个项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆