4

Is there a way of deploying a tomcat webapp with different web.xml (different name and context)?.

The problem:

I have a web.xml which i constantly have to modify (comment out and uncomment) stuff as i develop things - and this makes it a little annoying. Want i want to have is lets say two files:

web.xml
web-dev.xml

And I want my tomcat on my local machine to use web-dev.xml. Ofcouse for production release (i.e. Hosted server Tomcat will be using normal web.xml - web-dev.xml won't even be published). Its just for the development.

Any ideas where i can specify within tomcat to use web-dev.xml instead of web.xml ?

Thanks

Maciej Cygan
  • 5,351
  • 5
  • 38
  • 72

1 Answers1

2

Similarly to @HumbertoPinheiro, I think Maven profiles are a way to go.

Alternatively, this seems like a possible solution (Reference link : Specify a custom web.xml to an embedded tomcat):

Context webContext = tomcat.addWebapp("/yourContextPath", "/web/app/docroot/");
webContext.getServletContext().setAttribute(Globals.ALT_DD_ATTR, "/path/to/custom/web.xml");

Tested on Tomcat 7.0.42.

Community
  • 1
  • 1
Jakub Wach
  • 199
  • 1
  • 7