2

Is it possible to filter the web.xml file when packaging a war using Buildr?

Buildr documentation:

Without much prompting, package :war picks the contents of the src/main/webapp directory and places it at the root of the WAR

I have a place holder or token defined in the web.xml and I would like to replace it when packaging the war depending on which env I am building. What is the best way to go about it? Is there a filtering option for the package method?

Ross
  • 3,008
  • 1
  • 22
  • 27

1 Answers1

3

You can instruct Buildr to filter your resources under src/main/webapp and place the resulting files under target/webapp,

filter_webapp = file("target/webapp") do |task|
  filter('src/main/webapp/').into(task.to_s).using(
    'version' => '9999'
  ).run
end

then wire your new task with the resources tasks (which is implicitly required before packaging),

resources.enhance [filter_webapp]

and finally package the filtered resources,

package(:war).with(filter_webapp)

For more details about filtering, see http://buildr.apache.org/building.html#resources

Alex Boisvert
  • 2,850
  • 2
  • 19
  • 18
  • thanks Alex for the response. I haven't got it working yet though, will be away for couple of days but will continue with this when I am back – Ross Aug 04 '11 at 16:16
  • Hi Alex, this works thanks...reason it was failing earlier was with this error:ArgumentError : symbol string may not contain '\0' on line filter('src/main...). Narrowed it down to a jpeg file in my images folder...strange as the other jpegs / gifs / etc are fine. Soon as I remove that image it works – Ross Aug 04 '11 at 20:21
  • I get an `ArgumentError : interning empty string` at the second line. buildr --trace doesn't help me. – koppor May 04 '12 at 23:06
  • Is it possible to specify single files / a concrete set of files to be treated and not the complete directory? – koppor May 04 '12 at 23:34