Maciej Cygan
Maciej Cygan

Reputation: 5471

Deploy tomcat webapp with different web.xml

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

Upvotes: 4

Views: 1167

Answers (1)

Jakub Wach
Jakub Wach

Reputation: 199

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.

Upvotes: 2

Related Questions