This week's book giveaway is in the Design forum.
We're giving away four copies of Building Microservices and have Sam Newman on-line!
See this thread for details.
The moose likes Tomcat and the fly likes Setting up contexts somewhere other than webapps Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Building Microservices this week in the Design forum!
JavaRanch » Java Forums » Products » Tomcat
Bookmark "Setting up contexts somewhere other than webapps" Watch "Setting up contexts somewhere other than webapps" New topic

Setting up contexts somewhere other than webapps

Kannan Alagar

Joined: Apr 18, 2011
Posts: 4
Dear Sir,

I am using Java 6.0 and Tomcat 7.0. I am running jsp and servlet file using Tomcat 7.0. But all my files are stored like JSP File --> "C:\Program Files\Apache Software Foundation\Tomcat 7.0\webapps\examples\jsp" folder.

Like Servlet file --> "C:\Program Files\Apache Software Foundation\Tomcat 7.0\webapps\examples\WEB-INF\classes". But i want run jsp and servlet file in my user area (E:\Project). not apache examples folder.

How can i solve this problem

Glenn Rogers

Joined: Apr 24, 2009
Posts: 6
If I understand you correctly, you want to point the appbase to a new directory? If that is correct, you need to update conf/server.xml
and change appBase="E:/Project"

<Host name="localhost" appBase="webapps"
unpackWARs="true" autoDeploy="true"
xmlValidation="false" xmlNamespaceAware="false">
Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 63232

Or, without touching server.xml at all, you can specify whatever docbase you want in the context files.

[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Kannan Alagar

Joined: Apr 18, 2011
Posts: 4
Hello Glenn Rogers ,

i was changed in my appBase path in server.xml file

<Host name="localhost" appBase="E:/Project"
unpackWARs="true" autoDeploy="true"
xmlValidation="false" xmlNamespaceAware="false">

Now the Tomcat web server is not running.

How to setting up contexts.

Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 17046

First, unzip a fresh copy of your server.xml file from the Tomcat zip file you downloaded and installed from. Replace the server.xml you damaged with this original copy. Check to make sure Tomcat works again.

Tomcat is designed to host multiple web applications, not simply be a loose collection of servlets and JSPs, so you need to have defined an application to contain your servlets/JSPs, and it must be in WAR format. In the 100% pure J2EE spec, the WAR should be a single file in JAR format, but Tomcat also allows you to work with "exploded" WARs, which is the set of directories that you get when you unzip a WAR file. The directory that contains this exploded WAR is your docBase.

You can use a Context to define a webapp, and set its docBase to something like "E:/Projects/examples". To do that, you create a file named "XXXXXX.xml" containing a <Context> element and copy it to the TOMCAT_HOME/conf/Catalina/localhost directory. A Context looks something like this:

When you start up Tomcat, you should then be able to run your examples with URLs such as "http://localhost:8080/XXXXXX/test.jsp", where "XXXXXX" is the name of the XML file containing your Context definition. Please note that in this type of configuration the "path" attribute of the Context is not used to define the webapp's URL context. It uses the context filename (minus the .xml).

For best results, delete any directories and files under TOMCAT_HOME/webapps/examples (including the examples directory itself). They tend to take precedence over other webapp definitions, and may actually overwrite your XXXXXX.xml file in some cases.

An IDE is no substitute for an Intelligent Developer.
Kannan Alagar

Joined: Apr 18, 2011
Posts: 4
Hello Tim Holloway,

Thanks for your reply. I created xml file in TOMCAT_HOME/conf/Catalina/localhost directory. Now JSP file is running. How to run servlet file.

Kannan Alagar

Joined: Apr 18, 2011
Posts: 4
Hello Friends

Anybody how to run servlet file in Tomcat 7.0 other than webapps directory.
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link:
subject: Setting up contexts somewhere other than webapps
jQuery in Action, 3rd edition