Bootstrap FreeKB - IBM WebSphere - Context root of an application
IBM WebSphere - Context root of an application

Updated:   |  IBM WebSphere articles

Context root is the endpoint used to request a certain application. In this example, the context root is "/beta", which is used to get the beta application.

 

To determine the context root of an application

  1. In the WebSphere admin console, expand Applications > All applications.
  2. Select your application.
  3. Select Context Root for Web Modules. The context root will be displayed.

For example, the context root of the Beta application is /beta.

Likewise, the /opt/WebSphere/AppServer/profiles/your_profile/installedApps/your_cell/your.ear/META-INF/application.xml file may contain the Context Root.

<context-root>/beta</context-root>

 


Change context root

The context root can be changed by selecting Applications > All Applications > app > Context root for web modules, changing the context root, and then restarting the application server. However, this is not an ideal solution, because the context root would need to be fixed everytime the app is deployed. A much more reasonable solution will be to set the context root in the development tool, such as Eclipse.

If you are deploying an EAR, you would set the context root in the EarContent/WEB-INF/lib/application.xml file 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>

 

If you are deploying a WAR, you would set the context root in the WEB-INF/ibm-web-ext.xml file of the WAR.

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE xml>
<web-ext>
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xmlns="http://websphere.ibm.com/xml/ns/javaee"
  xsi:schemaLocation="http://websphere.ibm.com/xml/ns/javaee http://websphere.ibm.com/xml/ns/javaee/ibm-web-ext_1_0.xsd"
  version="1.0">
  <context-root uri="/beta"/>
</web-ext>

 


Deployment Descriptor

Technically, when the EAR or WAR is deployed, the deployment descriptor will have the context root of /beta. The deployment descriptor is the file that is read by WebSphere to set the context root. An applications deployment descriptor XML file can be viewed in the WebSphere admin console.  Or, the XML file can be viewed on the command line, at dmgr_home/profiles/your_profile/wstemp/######/workspace/cells/your_cell/application/your_app/deployments/your_app/META-INF/application.xml.

  1. In the WebSphere admin console, expand Applications and select All Applications.
  2. Select an application.
  3. Select View Deployment Descriptor.

In this example, the deployment descriptor file has a context root of /beta.

<application id="Application_ID" version="7" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/application_7.xsd" >
 <display-name> Delta </display-name>
 <initialize-in-order> False </initialize-in-order>
   <module id="Module_1521378866851" >
     <web>
       <web-uri> Beta.war </web-uri>
       <context-root> /beta </context-root>
     </web>
   </module>
</application>

 

Using the deployment descriptor file, the context root will be set to whatever context root is listed in the deployment descriptor file.

 

The application will be able to be requested using the context root.




Did you find this article helpful?

If so, consider buying me a coffee over at Buy Me A Coffee



Comments


May 12 2020 by ANUBHAV GUHA
VERY WELL EXPLAINED. THANKS FOR YOUR EFFORTS.

June 04 2020 by Ryan
Thanks, Jeremy. Was exactly what we needed!

Add a Comment


Please enter ef07bc in the box below so that we can be sure you are a human.