Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add a file to a war with Maven

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

like image 383
Maxence Avatar asked Mar 10 '10 09:03

Maxence


People also ask

How do I create a war file in Maven?

Using the mvn:war:exploded command, we can generate the exploded WAR as a directory inside the target directory. This is a normal directory, and all the files inside the WAR file are contained inside the exploded WAR directory.

How do I create a war file?

To create war file, you need to use jar tool of JDK. You need to use -c switch of jar, to create the war file. Go inside the project directory of your project (outside the WEB-INF), then write the following command: jar -cvf projectname.

What is war packaging in Maven?

Goals Overview war:war is the default goal invoked during the package phase for projects with a packaging type of war . It builds a WAR file. war:exploded is generally used to speed up testing during the developement phase by creating an exploded webapp in a specified directory.


1 Answers

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> 
like image 165
simonlord Avatar answered Oct 16 '22 09:10

simonlord