aspose file tools*
The moose likes Servlets and the fly likes context.xml + Help Needed Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "context.xml + Help Needed" Watch "context.xml + Help Needed" New topic

context.xml + Help Needed

Maneesh Chauahn
Ranch Hand

Joined: Mar 06, 2006
Posts: 48
I have the requirement to access the directory outside the build path of the web-application. So i created
a context.xml file and put this file in my webapplication web-inf folder. The context file contains the docbase that point
the absolute path of directory structure

Please let me know to access the resources outside the build path (like images , htmls files) what all steps i will be need

Maneesh Chauhan
Rahul verma

Joined: May 15, 2007
Posts: 7
you want to place your files images etc.. outside the webapps directory?
Maneesh Chauahn
Ranch Hand

Joined: Mar 06, 2006
Posts: 48
Yes i want to place the html files and images outside web directory
Ben Souther

Joined: Dec 11, 2004
Posts: 13410

Are you saying that you want your web application to exist outside of the container hierarchy or do you want to access files that are outside of your web application's directory structure.

Creating a context.xml file has nothing to do with the latter.
Please explain, in detail, what it is that you're trying to do.

Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Maneesh Chauahn
Ranch Hand

Joined: Mar 06, 2006
Posts: 48
I have some html files and images that are present in the build path of the web application. These files increased the size of the war file , but i want to put these files outside the build path (to other location).

So how can i access these html files and images which are outside the build path. I knew that i used file stream to access the same but is there any way to access the same means by using the context.xml file

Ben Souther

Joined: Dec 11, 2004
Posts: 13410


If you want to serve up static files from outside your web application, you'll need to write a servlet that streams them.

If your servlet container is being run in conjunction with a web server like Apache HTTPD, there are ways to route only JSP/Servlet requests to the container and allow the web server to serve up the static resources.
This is a lot of work to set up and maintain, just to reduce the size of a war file though.
Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 60041

These files increased the size of the war file

So? Why is this a concern?

[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Umashankara Kalaiah

Joined: Jun 13, 2007
Posts: 2
yes Ben Souther reply is correct. but you can do that in easy way. you don't need to write new servlet. you can have static resources in another webapplication.

below steps may help you to understand better
1) Have all your jsp's in one web application,lets say 'webapp1'
2) Have your all static source(like images and css files) in another webapplication, lets say 'webapp2'
have directory structure of images and css files in webapp2 like this

webapp2 -> web-inf |->config.xml
|->css ->css files
|->images -> image files

3) deploy both into appserver or web server
4) you can access webapp2 resources in webapp1 like this

/webapp2/images/*.jpg or /webapp2/images/*.css
Ben Souther

Joined: Dec 11, 2004
Posts: 13410

Welcome to JavaRanch!

We're pleased to have you here with us in the Servlets forum, but there
are a few rules that need to be followed, and one is that proper names are
required. Please take a look at the
JavaRanch Naming Policy and
adjust your display name to match it.

In particular, you can use initials for your first and middle names but not for your last name (surname)

You can change it here

Thank you,
I agree. Here's the link:
subject: context.xml + Help Needed
Similar Threads
Eclispe's Dynamic Web Project
Can't deploy war file outside of [tomcat]/webapps
how to access other folders outside webapp in tomcat6
Problems setting up website with context.xml inside META-INF
Reading a File in Servlet from Web App Directory