Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Francesco Bellini
Ranch Hand
Posts: 38
Linux Oracle Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 5852
7
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Francesco Bellini
Ranch Hand
Posts: 38
Linux Oracle Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic