简体   繁体   English

Maven(多模块项目)-在模块之间复制文件

[英]Maven (multimodule project) - Copy file between modules

I have a multimodule maven project, as follows: 我有一个多模块的Maven项目,如下所示:

module: project-assembly;
module: project-implementation;
module: project-application;
module: project-web;

in project-assembly/src/main/assembly/config i have important configuration files for my project, and i need them to be copied during build process into project-web module into WEB-INF folder. 在project-assembly / src / main / assembly / config中,我有用于项目的重要配置文件,在构建过程中需要将它们复制到project-web模块中,并复制到WEB-INF文件夹中。

More important, this has to be done with specific profile. 更重要的是,这必须通过特定的配置文件来完成。

For example, having a "x" profile, this is the one who needs this files in order to package successfully the project. 例如,拥有“ x”配置文件的用户就是需要此文件才能成功打包项目的用户。

is there a way to achieve this? 有没有办法做到这一点? Thanks 谢谢

you can use maven resource plugin- 您可以使用Maven资源插件-

<properties> 
<othermodule-dir>...</othermodule-dir>

</properties>

<build>
 <resources>
    <resource>
      <!-- package thumbnail -->
      <directory>${sourceDir}</directory>
      <targetPath>${othermodule-dir}</targetPath>
      <filtering>true</filtering>
    </resource>
  </resources>
.
.
</build>

You can use the maven-antrun-plugin to copy files between arbitrary folders (ant copy). 您可以使用maven-antrun-plugin在任意文件夹之间复制文件(ant副本)。 But I would strongly advise against copying between modules. 但是我强烈建议不要在模块之间进行复制。 It is confusing and even more: The build order or the subset of modules that are built are subject to change (depending on the dependencies and also the command line parameters). 这令人困惑,甚至更多:构建顺序或所构建模块的子集可能会更改(取决于依赖项以及命令行参数)。 For this copying, you need to make sure that the build happens in a defined order. 对于此复制,您需要确保构建按定义的顺序进行。

Think about sharing the configuration in another way. 考虑以另一种方式共享配置。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM