File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Ant, Maven and Other Build Tools and the fly likes Need to make maven war plugin copy some arbitrary files? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Engineering » Ant, Maven and Other Build Tools
Bookmark "Need to make maven war plugin copy some arbitrary files?" Watch "Need to make maven war plugin copy some arbitrary files?" New topic
Author

Need to make maven war plugin copy some arbitrary files?

Toby Eggitt
Ranch Hand

Joined: Dec 08, 2004
Posts: 41
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.
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 30075
    
149

Take a look at the copy resources plugin. It runs before the war plugin so you can copy the files to the right location in the war directory structure before the war plugin zips it up.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Toby Eggitt
Ranch Hand

Joined: Dec 08, 2004
Posts: 41
Thanks, that's helped. I have one remaining problem. When I configured it, I gave the "output" directory as target/Service-1.1-SNAPSHOT/sources, but clearly that's not very sensible. Can I refer to "the directory that this whole project is being dumped in" as a variable of some kind?

Thanks again!
Toby
Toby Eggitt
Ranch Hand

Joined: Dec 08, 2004
Posts: 41
OK, sorted it, thanks. I needed to use

<outputDirectory>target/${project.name}-${project.version}/sources ...

Thanks again.
Toby
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 30075
    
149

I like using ${project.build.directory} instead of target. I'm not sure if they are equivalent, but I know the former doesn't care about your current working directory.

And in case you haven't found it, there is a list of pre-defined Maven properties.
Toby Eggitt
Ranch Hand

Joined: Dec 08, 2004
Posts: 41
Oh, that looks useful, thanks. Particularly because when I build this thing locally, I know it goes to "target" but it also gets pushed to a CI system, so who knows what that does.

Thanks again!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Need to make maven war plugin copy some arbitrary files?
 
Similar Threads
Maven Java CORBA source generation
Web Development Environment Best Practices With Ant