File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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 OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Products » Tomcat
Bookmark "Setting up contexts somewhere other than webapps" Watch "Setting up contexts somewhere other than webapps" New topic
Author

Setting up contexts somewhere other than webapps

Kannan Alagar
Greenhorn

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
Greenhorn

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
Marshal

Joined: Jan 10, 2002
Posts: 61447
    
  67

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
Greenhorn

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.

Thanks
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16158
    
  21

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.


Customer surveys are for companies who didn't pay proper attention to begin with.
Kannan Alagar
Greenhorn

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
Greenhorn

Joined: Apr 18, 2011
Posts: 4
Hello Friends

Anybody how to run servlet file in Tomcat 7.0 other than webapps directory.
 
Consider Paul's rocket mass heater.
 
subject: Setting up contexts somewhere other than webapps