Copying file from one project to another in maven

痞子三分冷 提交于 2019-12-03 11:23:34

问题


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.

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


回答1:


You can do this with the maven resources plugin: copy-resources, something like:

<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.



来源:https://stackoverflow.com/questions/8386543/copying-file-from-one-project-to-another-in-maven

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!