Sometimes, it may happen, you want to provide the application context name different from the WAR file name while deploying in Tomcat.
Scenario:
WAR Name: ABC.war
The default url becomes: http://localhost:8080/ABC
Want to access the url as: http://localhost:8080/XYZ
Scenario:
WAR Name: ABC.war
The default url becomes: http://localhost:8080/ABC
Want to access the url as: http://localhost:8080/XYZ
There are 2 options available to do this change
Option #1:
Here is the steps that can be followed:
1. Navigate to <TOMCAT_HOME>/conf/server.xml
2. Goto the Host section & do the below changes
3. Change it to below:
<Host name="localhost" appBase="webapps"
unpackWARs="false" autoDeploy="false" deployOnStartup="false">
Please note, unpackWARs , deployOnStartup, autoDeploy all three should be marked as false, else 2 folders will be generated one with name ABC & another XYZ.
4. Add the context changes under Host
<Host name="localhost" appBase="webapps"
unpackWARs="false" autoDeploy="false" deployOnStartup="false">
<Context path="/XYZ" docBase="ABC.war"/>
<!-- other preexisting configuration-->
<Host>
5. Start Tomcat going to <TOMCAT_HOME>/bin/startup.bat (windows) or <TOMCAT_HOME>/bin/startup.sh in Linux environment.
Option #1:
Here is the steps that can be followed:
1. Navigate to <TOMCAT_HOME>/conf/server.xml
2. Goto the Host section & do the below changes
3. Change it to below:
<Host name="localhost" appBase="webapps"
unpackWARs="false" autoDeploy="false" deployOnStartup="false">
Please note, unpackWARs , deployOnStartup, autoDeploy all three should be marked as false, else 2 folders will be generated one with name ABC & another XYZ.
4. Add the context changes under Host
<Host name="localhost" appBase="webapps"
unpackWARs="false" autoDeploy="false" deployOnStartup="false">
<Context path="/XYZ" docBase="ABC.war"/>
<!-- other preexisting configuration-->
<Host>
5. Start Tomcat going to <TOMCAT_HOME>/bin/startup.bat (windows) or <TOMCAT_HOME>/bin/startup.sh in Linux environment.
Option#2:
- Explode the ABC.war (unzip the WAR file)
- Place the exploded WAR in a folder outside Tomcat Directory (e.g. D:\mywebapps)
- So, now the exploded WAR path will be D:\mywebapps\ABC
- Create an xml file in <TOMCAT_HOME>/conf/Catalina/localhost named XYZ.xml (the name of expected context)
- Now add the below line in XYZ.xml
- <Context path="/XYZ" docBase="D:/mywebapps/ABC"/>
- docBase refer to the path where exploded WAR is placed.
- Start Tomcat going to <TOMCAT_HOME>/bin/startup.bat (windows) or <TOMCAT_HOME>/bin/startup.sh in Linux environment.