Maven复制多模块项目中的资源 [英] Maven copy resources in multi module project

查看:110
本文介绍了Maven复制多模块项目中的资源的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的需求是非常基本的,但是我找不到任何明确的答案:我只需要能够在多模块项目中分配资源.

让我们考虑一下例如LICENSE文件,我在此假定它对于所有模块都是相同的.我不希望将其手动复制到每个模块中,因为文件可能会随着时间而变化.我也不想在项目文件夹之外静态链接到资源(即使使用相对路径),因为模块化结构也可能会更改.

是否有任何可用于可靠地确保每个模块都具有所需文件的插件?通过利用父项目的POM获得该副本或由模块化层次结构中的超级项目直接执行,这样的副本同样可以接受.

解决方案

您可以使用程序集和依赖插件. http://www. sonatype.com/people/2008/04/how-to-share-resources-across-projects-in-maven/

它描述了该选项..从2008年开始,但是maven已经存在了一段时间.

编辑有关评论
另一个选项是 maven-remote-resources-plugin . 有关更详细的示例,请参见:
http://maven.apache.org/plugins /maven-remote-resources-plugin/examples/sharing-resources.html

由于他们的介绍实际上是在为自己说话,所以我引用了(maven.apache.org)

此插件用于从远程存储库检索资源JAR,处理这些资源,并将其合并到您使用Maven构建的JAR中.一个非常常见的用例是需要在整个组织中以一致的方式打包某些资源:在Apache上,要求每个产生的JAR都包含Apache许可证的副本和一个引用文件,该文件引用给定项目中的所有已使用软件.

My need is pretty basic but I could not find any clean answer to it: I simply need to be able to distribute a resource in a multi-module project.

Let us consider for example the LICENSE file, which I hereby assume to be the same for all modules. I prefer not to manually copy it into each and every module because the file could change over time. I also prefer not to statically link to resources (even if using relative paths) outside the project folder, because the modular structure can possibly change too.

Is there any plugin that can be used to robustly guarantee that each module is given the required file? It would be equally acceptable for such copy to be obtained by exploiting the POM of the parent project or directly performed by the super project in the modular hierarchy.

解决方案

you could use the assembly and the dependency plugins.. did you stumble over that link? http://www.sonatype.com/people/2008/04/how-to-share-resources-across-projects-in-maven/

it describes that option ..its from 2008, but maven is around for quite some time.. so I guess its more or less up to date

edit regarding comment
Another option is the maven-remote-resources-plugin. For a more detailed example see:
http://maven.apache.org/plugins/maven-remote-resources-plugin/examples/sharing-resources.html

Since their intro speaks actually for itself, I quote (maven.apache.org)

This plugin is used to retrieve JARs of resources from remote repositories, process those resources, and incorporate them into JARs you build with Maven. A very common use-case is the need to package certain resources in a consistent way across your organization: at Apache it is required that every JAR produced contains a copy of the Apache license and a notice file that references all used software in a given project.

这篇关于Maven复制多模块项目中的资源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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