Meaningless Drivel is fun!
The moose likes Servlets and the fly likes context path in java class Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "context path in java class" Watch "context path in java class" New topic

context path in java class

Avinash venna

Joined: Jun 10, 2010
Posts: 17
Hi all,

i am using servlets and jsp's for my web application... through servlet i am calling a java class and that class reads a property file.. when i am working on eclipse i gave the absolute path for the file.. but after deploying the class is unable to retrieve the exact path... someone please help me how to give a file location in web context (this file is read by a normal java class.. not a servlet or jsp)
Rahul Nair
Ranch Hand

Joined: Dec 01, 2007
Posts: 138
Hi Avinash,

In servlet you are calling a java class means at the top, you should have written import statement for that class. Then in that case there should not be any problem after deploying the class... Can you please share some line of code so that we can investigate it ?


Nilesh Miskin
Ranch Hand

Joined: Jun 17, 2010
Posts: 44
Always use paths that are relative to the context root of the web app. That way you can ensure that your class gets the desired resources.

Nilesh Miskin
Amol Nayak
Ranch Hand

Joined: Oct 26, 2006
Posts: 218
use the getResourceAsStream() method of the ServletContext to read the properties file as stream. I am assuming your properties file is not outside the web application

Since your are reading the properties file in a non servlet class, get the stream in a servlet and pass the InputStream to your java class.
I agree. Here's the link:
subject: context path in java class
It's not a secret anymore!