Java - Context Root
by
Jeremy Canfield |
Updated: March 23 2022
| Java articles
Let's say you are deploying a Java application to an application server such as JBoss, Tomcat, or WebSphere, where the URL for the application server is http://www.example.com:9080. In this scenario, if the context root of your Java application is /beta, then you would be able to request your application at http://www.example.com:9080/beta.
There are a few different ways to define the context root.
- In application.xml of an EAR
- In an XML file in your WAR
- sun-web.xml for Glassfish
- jboss-web.xml for JBoss
- weblogic.xml for WebLogic
- context.xml for Tomcat
- ibm-web-ext.xml for IBM WebSphere
- Using the name of your WAR
application.xml EAR
If you are deploying an EAR, you would set the context root in the application.xml file. The application.xml file will reside in the /WEB-INF/lib/ directory of the EAR. In this example, the display name of the EAR is Delta, and the context root of the Beta.war in the EAR is /beta.
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE xml>
<application id="Application ID" version="7">
<display-name>Delta</display-name>
<module id="Module_123456789">
<web>
<web-uri>Beta.war</web-uri>
<context-root>/beta</context-root>
</web>
</module>
</application>
Did you find this article helpful?
If so, consider buying me a coffee over at