Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Using relative path in java programs - how ?

Reply
Thread Tools

Using relative path in java programs - how ?

 
 
Guy
Guest
Posts: n/a
 
      06-15-2004
Hi

I wrote a new servlet that uses a configuration file to store
parameters.
The problem is that I want to use a relative path when accessing this
file, since I dont know where this servlet will be deployed.
Basically, I want it to be in the same directory where the .class
files are located.

Using the property user.dir does'nt help because it returns the
server's executable path.

How can I control this ? how can the program "know" where the class
files are ?
 
Reply With Quote
 
 
 
 
Dan Gravell
Guest
Posts: n/a
 
      06-15-2004
Guy wrote:

> Hi
>
> I wrote a new servlet that uses a configuration file to store
> parameters.
> The problem is that I want to use a relative path when accessing this
> file, since I dont know where this servlet will be deployed.
> Basically, I want it to be in the same directory where the .class
> files are located.
>
> Using the property user.dir does'nt help because it returns the
> server's executable path.
>
> How can I control this ? how can the program "know" where the class
> files are ?


Look at the ServletContext object, which you should be able to get from
your Servlet. You normally place the config file somewhere like WEB-INF
and then do a getResource() or getResourceAsStream() (sorry I can't
remember specifics, it's been a while).

Dan
 
Reply With Quote
 
 
 
 
Andrew Thompson
Guest
Posts: n/a
 
      06-15-2004
On 15 Jun 2004 00:59:00 -0700, Guy wrote:
...
> I wrote a new servlet that uses a configuration file to store
> parameters.
> The problem is that I want to use a relative path when accessing this
> file, since I dont know where this servlet will be deployed.


Put the config. file in a known place on the
server (the servlet is another matter), then..
URL url = getServletContext().getResource(fileName);

But then, I understand the accepted way to
configure servlets is by adding the information
to the deployment descriptor and invoking...

String param = ServletContext.getInitParameter(name);

--
Andrew Thompson
http://www.PhySci.org/ Open-source software suite
http://www.PhySci.org/codes/ Web & IT Help
http://www.1point1C.org/ Science & Technology
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
FileUpload control doesn't work (fail in client side early stages) when path is relative i.e "\\path.." Oren ASP .Net 1 04-29-2007 04:20 PM
How do I convert an absolute path into a relative path Nigel Wilkinson Ruby 2 07-25-2005 07:37 PM
absolute path versus relative path in JSP Matt Java 3 07-08-2004 08:31 PM
Re: How do you use a Relative Path to locate a Schema using Java? thefirstwml XML 1 04-19-2004 02:04 PM
Make a relative url path from an absolute path to another one Thomas Guettler Python 3 10-27-2003 04:41 PM



Advertisments