location of config files and path confusion

Discussion in 'Java' started by Tom Forsmo, May 1, 2007.

  1. Tom Forsmo

    Tom Forsmo Guest

    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
    Tom Forsmo, May 1, 2007
    #1
    1. Advertising

  2. 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/
    Knute Johnson, May 1, 2007
    #2
    1. Advertising

  3. Tom Forsmo

    Lew Guest

    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.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/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/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.

    --
    Lew
    Lew, May 1, 2007
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Patrick Olurotimi Ige

    Web.Config (location path=)Question

    Patrick Olurotimi Ige, Apr 4, 2005, in forum: ASP .Net
    Replies:
    4
    Views:
    52,209
    grchuah
    Nov 5, 2006
  2. Patrick Olurotimi Ige

    location path in Web.config

    Patrick Olurotimi Ige, May 12, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    1,988
    Brock Allen
    May 12, 2005
  3. CSharpner
    Replies:
    0
    Views:
    980
    CSharpner
    Apr 9, 2007
  4. luqman
    Replies:
    2
    Views:
    782
    luqman
    Jul 11, 2007
  5. mpaine
    Replies:
    0
    Views:
    1,158
    mpaine
    Mar 25, 2010
Loading...

Share This Page