Welcome to my Tomcat tutorials website!

sabato 10 maggio 2014

Tomcat Context Path configuration

Tomcat context path configuration

Every time we deploy an application we need to setup a context path for the application. The context path will be used for accessing the application from a browser:
http://SERVER:PORT/Context-Path/Resource
Even if it's actually possible to deploy an application on the Root Context Path ("/") this is usually reserved in special cases, for example if you need to provide a welcome page for your server or in other circumstances.

Enabling a context path

The context path in Tomcat can be enabled in two ways:

  • GUI using the Tomcat Web Application Manager
  • Command-line configuration in server.xml

In order to enable Context Path using the GUI interface, login into the Tomcat Application Manager:

You can create the context path using the Deploy tab.

Click on Browse and select the required WAR file. Then click on Deploy. It will take some seconds seconds to deploy the application (based on the application size) .
The following screenshot shows the application deployment status and administrative controls such as Stop, Reload, and Undeploy:

Once the application is deployed successfully, you can browse the application using its Context Path.

Command-line configuration in server.xml

Another way of adding the context path in Tomcat 7 is by editing server.xml. Let's quickly discuss the changes that need to be done on the Tomcat server:

<Context path="/myapplication" docBase="/www/" reloadable="true"
swallowOutput="true">
<WatchedResource>WEB-INF/web.xml</WatchedResource>
<Logger className="org.apache.catalina.logger.FileLogger"
prefix="www-sample-com-log." suffix=".txt"
timestamp="true"/>
</Context>

Now, it's time to discuss the parameters defined in the context path:

  • path="/myapplication": It defines the path URL for the server request, for example, http://localhost:8080/myapplication
  • docBase="/www/": It defines the document root for the context path. In simple language, this parameter defines the place from where the deployment .war file gets picked up.
  • reloadable="true": If this parameter is true, then every change done on the WAR file will be in effect automatically without a Tomcat recycle.
  • swallowOutput="true": If this parameter is set to true, then the output for System.out and System.err will be redirected to the application log.

Nessun commento:

Posta un commento