Search code examples
buildr

Buildr - Filter web.xml in packaging war


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?


Solution

  • 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