How to add a file to a war with Maven

拥有回忆 提交于 2019-11-29 08:40:22

问题


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

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

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


回答1:


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

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

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.

Hope that helps.

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


来源:https://stackoverflow.com/questions/2415610/how-to-add-a-file-to-a-war-with-maven

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