2011-12-05 105 views
13

我正在开发一个多模块项目。我们在少数其他模块中使用来自一个模块的appCtx.xml。在maven中将文件从一个项目复制到另一个项目

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

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

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

+0

你能添加一个直接的依赖吗? – Gray

+1

另一个想法是使用您的修订控制系统来提供帮助。我不知道,如果你使用SVN但见:http://stackoverflow.com/questions/1401951/is-it-possible-to-link-svn-repository-files-so-that-a-file-is-其实是一个参考 – Gray

回答

35

您可以用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> 

此副本从一个项目(共置在同一个源代码树)的文件作为生成资源阶段的一部分。您可以根据自己的需求进行调整。

这从一个项目复制到另一个可能导致不稳定的构建,如果项目不是一次性全部建成,但上面会为它们总是一起建立的项目。

+1

我一直在找它!谢谢 –

相关问题