How do you specify the root context in your <web-app> tags in web.xml?

JavaTomcatJbossJetty

Java Problem Overview


I would like to specify the root context of my Java web application in my WAR file. How can I do this using valid web-app XML in a web.xml file?

Oh, yes I would like to do this in an application server agnostic way.

Java Solutions


Solution 1 - Java

This can't be done in an appserver agnostic way. Context root isn't part of the standard web.xml file. It's either specified when you deploy the app or in an appserver specific descriptor.

Note: the above applies to deploying WAR files. EAR files are a different story and the context can be specified as part of the application.xml deployment descriptor.

Solution 2 - Java

You can use like this in web.xml.

<env-entry>
		<description>web app</description>	
		<env-entry-name>appCxtRoot</env-entry-name>
		<env-entry-type>java.lang.String</env-entry-type>		
		<env-entry-value>webapp-@context-root-value@</env-entry-value>
	</env-entry>

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionsewardrobertView Question on Stackoverflow
Solution 1 - JavacletusView Answer on Stackoverflow
Solution 2 - JavaPerkyView Answer on Stackoverflow