Reading properties file from WEB-INF/classes

Discussion in 'Java' started by Dundonald, Oct 7, 2007.

  1. Dundonald

    Dundonald Guest

    Properties file stored in WEB-INF/classes.

    There are numerous ways to read properties files, but I'd like to know
    what your opinions are on the best way to read from the WEB-INF/
    classes directory given that I could deploy my war file to any server
    on any platform not knowing how a server is configured, i.e. with its
    real paths etc.
    Dundonald, Oct 7, 2007
    #1
    1. Advertising

  2. On Oct 7, 1:23 am, Dundonald <> wrote:
    > Properties file stored in WEB-INF/classes.
    >
    > There are numerous ways to read properties files, but I'd like to know
    > what your opinions are on the best way to read from the WEB-INF/
    > classes directory given that I could deploy my war file to any server
    > on any platform not knowing how a server is configured, i.e. with its
    > real paths etc.


    getResourceAsStream() should give you the resouece that is in WEB-INF/
    classes.

    http://java.sun.com/j2se/1.4.2/docs...der.html#getResourceAsStream(java.lang.String)

    -cheers,
    Manish
    Manish Pandit, Oct 7, 2007
    #2
    1. Advertising

  3. Dundonald

    Lew Guest

    Dundonald wrote:
    >> Properties file stored in WEB-INF/classes.
    >>
    >> There are numerous ways to read properties files, but I'd like to know
    >> what your opinions are on the best way to read from the WEB-INF/
    >> classes directory given that I could deploy my war [sic] file to any server
    >> on any platform not knowing how a server is configured, i.e. with its
    >> real paths etc.


    Manish Pandit wrote:
    > getResourceAsStream() should give you the resouece that is in WEB-INF/
    > classes.
    >
    > http://java.sun.com/j2se/1.4.2/docs...der.html#getResourceAsStream(java.lang.String)

    (Also available from java.lang.Class.)

    <http://java.sun.com/javaee/5/docs/api/javax/servlet/ServletContext.html#getResourceAsStream(java.lang.String)>
    will do the same thing rooted at the application context.
    > Returns the resource located at the named path as an InputStream object.

    ....
    > The path must begin with a "/" and is interpreted as relative to the current context root.

    ....
    > This method is different from java.lang.Class.getResourceAsStream,
    > which uses a class loader.
    > This method allows servlet containers to make a resource available to a servlet from
    > any location, without using a class loader.


    --
    Lew
    Lew, Oct 7, 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. pradeep gummi
    Replies:
    1
    Views:
    921
    dhek bhun kho
    Sep 5, 2003
  2. M
    Replies:
    5
    Views:
    421
    Christophe Vanfleteren
    Sep 20, 2003
  3. Matthew Macchia
    Replies:
    3
    Views:
    1,051
    Roedy Green
    Apr 13, 2004
  4. Hans
    Replies:
    3
    Views:
    2,450
    Ryan Stewart
    May 16, 2004
  5. Jim Bancroft

    reading a file from WEB-INF?

    Jim Bancroft, Nov 18, 2006, in forum: Java
    Replies:
    2
    Views:
    2,144
Loading...

Share This Page