What is context path in a web application
Context path, also called context root is the name with which a web application is accessed in the browser. It is the string after the server ip and port in the application URL.
http://127.0.0.1:8080/employee-manager
, then employee-manager
is the context path or context root of the application.Default context path
By default, the name of WAR becomes the context path of the application. Thus, if the name of your WAR is temperature-converter.war, then your application will be accessed at URL
http://127.0.0.1:8080/temperature-converter
assuming that the server is running at ip 127.0.0.1 and port 8080.If you want to customize the context root of your application so that it can be accessed at URL
http://127.0.0.1:8080/myApp
, then create a file named jboss-web.xml file inside WEB-INF folder of your WAR file with contents as below. <?xml version=”1.0″ encoding=”UTF-8″?>
<jboss-web>
<context-root>myApp</context-root>
</jboss-web>
In development environment, if you are using eclipse IDE or Spring Tool Suite, then the location of jboss-web.xml should be in src/main/webapp/WEB-INF folder.
Order of preference
If jboss-web.xml file is present at the above specified location in your application, then it will be given first or highest preference.
If it is not present and your application is an EAR file, then the value defined in the context-root
element of its application.xml will be considered as context path.
If both are not present, then the name of WAR will be the context path.