Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / May 2007

Tip: Looking for answers? Try searching our database.

location of config files and path confusion

Thread view: 
Tom Forsmo - 01 May 2007 16:10 GMT
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
Knute Johnson - 01 May 2007 18:12 GMT
> Hi
>
[quoted text clipped - 24 lines]
>
> 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

Signature

Knute Johnson
email s/nospam/knute/

Lew - 01 May 2007 23:18 GMT
> 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
[quoted text clipped - 9 lines]
> 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#getResourceAsSt
ream(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.Inp
utStream
)>
and its variants do the same.

<http://java.sun.com/j2ee/1.4/docs/api/javax/servlet/ServletContext.html#getResou
rceAsStream(java.lang.String
)>
in conjunction with
<http://java.sun.com/j2ee/1.4/docs/api/javax/servlet/ServletContext.html#getRealP
ath(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(jav
a.lang.Class
[])>
get resources via their URLs.

Signature

Lew



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.