Maven war plugin copy arbitrary files

Toby Eggitt picture Toby Eggitt · Nov 15, 2013 · Viewed 8.3k times · Source

I apologize that this is surely basic maven/war plugin stuff, but I'm totally not a maven user. I just have to hack this one thing into a project that is maven based.

What I need to do is to copy an (essentially arbitrary) directory and files into the root of my war. I need them to appear as resources available via HTTP when the war deploys.

I cannot simply put them in the "right place" in the source tree. This is because the files in question are actually the source files of my project. I realize this is a bit odd, but this is a documentation project, and I need to show the source and the effect all in the same war.

So, in the general case, how would I configure the maven war plugin to copy a given directory, along with it's contents, to the root of my war? (BTW, I have tried to make sense of the documentation of this tool, but it seems to be predicated on so much understanding of maven that it feels like I'll never understand it without learning maven first, and I'm a bit too pressed for time to do that just now!)

Many TIA Toby.

Answer

Drew MacInnis picture Drew MacInnis · Nov 15, 2013

You could try:

  1. use the copy-resources plugin. Use the plugin to copy your source files under target prior to when the war is packaged.

  2. or, configure the maven-war-plugin to include additional resources.