Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > location of config files and path confusion

Reply
Thread Tools

location of config files and path confusion

 
 
Tom Forsmo
Guest
Posts: n/a
 
      05-01-2007
Hi

I keep having problems with file paths in java. Every time I have to
make a file available, mostly a config file of some sort, to the
application I keep having problems specifying the correct path to the
file. There seems to be many different syntaxes for doing this and I
dont understand fully which do what and how.

I have tried to find some information about this on the net, but have
not been able to find something that fully explains this.

Here are some specific examples of paths issues I have.

log4j
spring
java properties files

The question is: where do I put the config file and how do I specify the
path to where the config file is to be found? I have noticed that some
use the "classpath:" to specify a config file that is to be found
somewhere in the classpaths, I have also noticed that some require the
config file to be in the same directory as the class resides in.
I have not figured out how to specify a path to a file outside the
classpath dorectoru paths, eg. in a separate conf/ directory.

Some help or guidance is much appreciacted, thanks

tom
 
Reply With Quote
 
 
 
 
Knute Johnson
Guest
Posts: n/a
 
      05-01-2007
Tom Forsmo wrote:
> Hi
>
> I keep having problems with file paths in java. Every time I have to
> make a file available, mostly a config file of some sort, to the
> application I keep having problems specifying the correct path to the
> file. There seems to be many different syntaxes for doing this and I
> dont understand fully which do what and how.
>
> I have tried to find some information about this on the net, but have
> not been able to find something that fully explains this.
>
> Here are some specific examples of paths issues I have.
>
> log4j
> spring
> java properties files
>
> The question is: where do I put the config file and how do I specify the
> path to where the config file is to be found? I have noticed that some
> use the "classpath:" to specify a config file that is to be found
> somewhere in the classpaths, I have also noticed that some require the
> config file to be in the same directory as the class resides in.
> I have not figured out how to specify a path to a file outside the
> classpath dorectoru paths, eg. in a separate conf/ directory.
>
> Some help or guidance is much appreciacted, thanks
>
> tom


I don't know anything about log4j or spring but the Java Properties
class loads it's data from an InputStream. An InputStream can be
created easily from a File and several other sources. File syntax and
methods are pretty straight forward. The description of abstract
pathnames in the docs for File is where you need to look. Also write
your self a program to list out the System Properties. There you will
find many useful properties for creating abstract pathnames such as;

file.separator
path.separator
user.dir
user.home
java.home

--

Knute Johnson
email s/nospam/knute/
 
Reply With Quote
 
 
 
 
Lew
Guest
Posts: n/a
 
      05-01-2007
Knute Johnson wrote:
> I don't know anything about log4j or spring but the Java Properties
> class loads it's data from an InputStream. An InputStream can be
> created easily from a File and several other sources. File syntax and
> methods are pretty straight forward. The description of abstract
> pathnames in the docs for File is where you need to look. Also write
> your self a program to list out the System Properties. There you will
> find many useful properties for creating abstract pathnames such as;
>
> file.separator
> path.separator
> user.dir
> user.home
> java.home


Some of which are completely irrelevant in a web application.

<http://java.sun.com/javase/6/docs/api/java/lang/ClassLoader.html#getResourceAsStream(java.lang.Str ing)>
gets a resource relative to the first classpath element that has it.

<http://java.sun.com/javase/6/docs/api/java/util/Properties.html#load(java.io.InputStream)>
and its variants do the same.

<http://java.sun.com/j2ee/1.4/docs/api/javax/servlet/ServletContext.html#getResourceAsStream(java.lang. String)>
in conjunction with
<http://java.sun.com/j2ee/1.4/docs/api/javax/servlet/ServletContext.html#getRealPath(java.lang.String)>
gets a resource relative to the web-app context.

<http://java.sun.com/javase/6/docs/api/java/net/URL.html#URL(java.lang.String)>
and its get...() methods like
<http://java.sun.com/javase/6/docs/ap...ava.lang.Class[])>
and related methods such as
<http://java.sun.com/javase/6/docs/ap...ava.lang.Class[])>
get resources via their URLs.

--
Lew
 
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
dll config and web.config and Label Expressions (binding label text to dll config settings) CSharpner ASP .Net 0 04-09-2007 09:00 PM
Location, location, location =?Utf-8?B?VHJhY2V5?= Wireless Networking 2 02-17-2007 08:37 PM
Web.Config (location path=)Question Patrick Olurotimi Ige ASP .Net 4 11-05-2006 02:10 AM
location path in Web.config Patrick Olurotimi Ige ASP .Net 1 05-12-2005 03:25 PM
Confusion about location of Mozilla files (Mandrake Linux 10.0) Hallvard Tangeraas Firefox 0 09-14-2004 09:46 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57