vicker313 tech blog

August 8, 2009

Add Tomcat Virtual Directory

Filed under: Tomcat — Tags: , — vicker313 @ 8:00 am

In Apache Tomcat, if we want to add a sub directory into an url, such as, we will normally create a new directory at the [tomcat]\webapp directory, and put in the necessary web pages.

However if we need to put the web pages outside webapp, then we need to create a virtual directory in Tomcat:

  1. Go to [tomcat]\conf\Catalina\localhost (version that I used is 5.5).
  2. Create a xml file, named it as the name of the directory that store your web pages, for example subdir.xml.
  3. Put in the following code (assume your directory is c:\subdir):
    <?xml version="1.0" encoding="UTF-8"?>
    <Context path="/subdir" docBase="c:/subdir" debug="0" privileged="true"></Context>
  4. Now you can access the site

It is also possible to point the virtual directory to a shared folder of another machine:

<Context path="/subdir" docBase="//" debug="0" privileged="true"></Context>

Beware that the directory that you point must have the web pages, as lease an index.html. Or else it will just show out no resource error message (will not list out the content of the directory).



  1. Hi , Is it possible use the subdirectory in the directory just given.
    eg : localhost/test is new link , that points to D:/test
    I need to show D:/test/test2/index.html.. Giving this leads tomacat again to the default path. Why is this happening??

    Comment by — December 4, 2012 @ 7:38 pm

    • have you ever try this?:

      <Context path=”/test” docBase=”d:/test/test2″ debug=”0″ privileged=”true”></Context>

      Comment by vicker313 — December 4, 2012 @ 7:53 pm

RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

Create a free website or blog at

%d bloggers like this: