location of config files and path confusion

T

Tom Forsmo

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
 
K

Knute Johnson

Tom said:
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
 
L

Lew

Knute said:
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/a...er.html#getResourceAsStream(java.lang.String)>
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/a...xt.html#getResourceAsStream(java.lang.String)>
in conjunction with
<http://java.sun.com/j2ee/1.4/docs/a...letContext.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/api/java/net/URL.html#getContent(java.lang.Class[])>
and related methods such as
<http://java.sun.com/javase/6/docs/api/java/net/URLConnection.html#getContent(java.lang.Class[])>
get resources via their URLs.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,991
Messages
2,570,217
Members
46,805
Latest member
ClydeHeld1

Latest Threads

Top