loading config file

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Moth

    loading config file

    Probably a simple question. I've written a web app that loads configuration
    info from an xml file. What is the best way to tell my app where that file
    is located? This app needs to run on both windows on linux machines...


  • Pipo

    #2
    Re: loading config file

    Moth wrote:[color=blue]
    > Probably a simple question. I've written a web app that loads configuration
    > info from an xml file. What is the best way to tell my app where that file
    > is located? This app needs to run on both windows on linux machines...
    >
    >[/color]
    there are a lot of solutions for this issue,
    but I'll just give you the ones I would use myself.

    1 - Place the file in the WEB-INF directory and call it from your
    servlet and/or jsp file with:

    getServletConte xt().getResourc eAsStream("/WEB-INF/<your config file>");

    or

    getClass().getR esourceAsStream ("/WEB-INF/<your config file>");

    2 - Place it in the classes directory under WEB-INF and
    call:

    getClass().getR esourceAsStream ("/<your config file>"");


    Hope it helps,
    Lau.

    Comment

    • Raymond DeCampo

      #3
      Re: loading config file

      Moth wrote:[color=blue]
      > Probably a simple question. I've written a web app that loads configuration
      > info from an xml file. What is the best way to tell my app where that file
      > is located? This app needs to run on both windows on linux machines...
      >
      >[/color]

      Place the file in the CLASSPATH and use ClassLoader.get Resource(). This
      will work in all environments (servelt, applet, application, etc.).

      Ray

      Comment

      • hiwa

        #4
        Re: loading config file

        "Moth" <no@email.her e> wrote in message news:<gWGLb.327 4$Wa.2166@news-server.bigpond. net.au>...[color=blue]
        > Probably a simple question. I've written a web app that loads configuration
        > info from an xml file. What is the best way to tell my app where that file
        > is located? This app needs to run on both windows on linux machines...[/color]
        Use Class#getResour ceAsStream(), and preferably, you might want to
        make a war file.

        Comment

        Working...