Results 1 to 3 of 3

Thread: dynamic web project in eclipse, reading resource file

  1. #1
    Join Date
    Oct 2007
    Beans
    411

    dynamic web project in eclipse, reading resource file

    Hi,
    I have a dynamic web web project, and in it I have a class that has some simple static methods, one of which is to read params from a config file.

    In the utility class, which is located under the source folder under com.somepackage, I create a new file object:

    Code:
    File configFile = new File("config/config.xml");
    When I run it, I get a null pointer...it says the file location doesn't exist.

    The config folder is under WebContent.

    I've tried various things; WebContent/config/config.xml, ./config/config.xml, etc...

    What's the best way to grab that file?
    thanks!
    bp

  2. #2
    Join Date
    Apr 2008
    Beans
    507

    Re: dynamic web project in eclipse, reading resource file

    You need to call getRealPath() from the ServletContext to obtain the physical path from the relative path.

    Code:
    File f = new File(getServletContext().getRealPath(relativePath));
    http://download.oracle.com/javaee/1....va.lang.String)
    Go you good thing!

  3. #3
    Join Date
    Oct 2007
    Beans
    411

    Re: dynamic web project in eclipse, reading resource file

    schweeeet....that did it!

    thanks!
    bp

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •