如何使用Maven将文件添加到战争中 [英] How to add a file to a war with Maven

查看:98
本文介绍了如何使用Maven将文件添加到战争中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经开发了一个maven插件,可以从JIRA下载发行说明. 默认情况下,它绑定到生成源"阶段,并在构建文件夹($ {project.build.directory})中创建一个"release.txt"文件.

I have developed a maven plugin that downloads the release notes from JIRA. It's bound by default to the 'generate-sources' phase and creates a 'release.txt' file in the build folder (${project.build.directory}).

我的问题:我如何在Maven构建的war文件的'WEB-INF'文件夹中添加此文件?

My question: how can I add this file in the 'WEB-INF' folder of the war file built by Maven ?

我知道我可以使用'maven-war-plugin'来包含'src'文件夹中的其他外部资源,但是我不希望在那里生成我的'release.txt'文件(=不可提交给svn)

I know I can use the 'maven-war-plugin' to include additional external resources from the 'src' folder, but I don't want my 'release.txt' file generated there (=not commitable to svn).

感谢您的帮助.祝您有美好的一天!

Thanks for your help. I wish you a nice day!

Maxence

推荐答案

我认为可以使用该插件的以下功能来做到这一点:

I think this can be done using this feature of that plugin:

添加和过滤外部Web资源: http://maven.apache.org/plugins /maven-war-plugin/examples/adding-filtering-webresources.html

Adding and Filtering External Web Resources: http://maven.apache.org/plugins/maven-war-plugin/examples/adding-filtering-webresources.html

这将允许您将release.txt生成到单独的文件夹(而不是src)中,并使插件将其视为额外的资源文件夹.

Which would allow you to generate your release.txt into a separate folder (not src) and have the plugin treat it as an extra resources folder.

希望有帮助.

<plugin> 
  <groupId>org.apache.maven.plugins</groupId> 
  <artifactId>maven-war-plugin</artifactId> 
  <configuration> 
    <webResources> 
      <resource> 
        <directory>${project.build.directory}</directory> 
        <targetPath>WEB-INF</targetPath> <!-- introduced in plugin v 2.1 -->
        <includes> 
          <include>release.txt</include> 
        </includes> 
      </resource> 
    </webResources> 
  </configuration> 
</plugin> 

这篇关于如何使用Maven将文件添加到战争中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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