aspose file tools*
The moose likes Ant, Maven and Other Build Tools and the fly likes Programmatically select web.xml to be Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » Ant, Maven and Other Build Tools
Bookmark "Programmatically select web.xml to be "built" depending on profile" Watch "Programmatically select web.xml to be "built" depending on profile" New topic
Author

Programmatically select web.xml to be "built" depending on profile

Francesco Bellini
Greenhorn

Joined: Nov 01, 2012
Posts: 26

Hello,

I am developing a web application that uses a web.xml file.
During the development phase on my PC I need to use some Servlet that I don't want to use on my testing environment at work.
Is it possible to tell Maven to built using a different web.xml file when building using a different profile?

Or is it possible to setup a script used by maven that removes the parts I don't need within my web.xml file?
Peter Johnson
author
Bartender

Joined: May 14, 2008
Posts: 5837
    
    7

Yes you can do this.

One way: Add a <build> section to you profile and add a <plugin> section fort he WAR plugin, then for each profile specify a different web.xml

Another way: have one web.xml which contains property references (e.g. ${production.stuff}). Then have two profiles, one that sets production.stuff to an empty string and the other that sets production.stuff to the web.xml content you want to include in your dev environment.

I make extensive use of the second option above for a number of things, including log4j settings and various tweaks that I use while testing. Also, I usually have only one profile which I use for setting development options, and it is in my settings.xml file - in the POM I set the production property values. This way the build machine picks up only the production values without having to set and specific profile, and my development build picks up my settings.


JBoss In Action
Francesco Bellini
Greenhorn

Joined: Nov 01, 2012
Posts: 26

Thank you Peter,

I will try this as soon as possibile. For me, solution 1 seems to be more confortable. ;) I will do some test.
 
jQuery in Action, 2nd edition
 
subject: Programmatically select web.xml to be "built" depending on profile