Creating new files in an existing deployed war file.

Discussion in 'Java' started by Ben Jessel, Nov 3, 2003.

  1. Ben Jessel

    Ben Jessel Guest

    I have a web application that is contained in a war file. I have a
    requirement to generate an xml file ( will be an rss field ), that can
    be accessible at a given url within my web application. This file
    could be quite big, so I can't just generate it on the fly per
    request. Nor can I cache it in session data.

    I'd prefer to deploy my application in war, rather than exploded-war
    format ( portability being a large concern.... ), however given I need
    to generate this xml file and save it in a directory of my web-app
    root, I think my only option is to revert to exploded war use.

    Is there any way of programatically creating/updating a file within
    say, the my-app war from a servlet in the war itself?

    My alternative strategies are

    1) saving the xml to the database ( something that the purist in me
    hates the idea of ).
    2) pushing the file to another server.

    Thanks
    Ben Jessel, Nov 3, 2003
    #1
    1. Advertising

  2. Ben Jessel

    Ben_ Guest

    You needn't necessarily create it in the root of your project: you can
    create it somewhere else (File.createTempFile) and create a servlet to
    stream the actual content.

    You could also create it under the root of your app (with
    ServletContext.getRealPath) but you must ensure your WAR file is exploded.
    If not, you could zip a new entry in the War file with the Zip API (will the
    purist you claim to be like this ? :))).
    Ben_, Nov 3, 2003
    #2
    1. Advertising

  3. Ben Jessel wrote:

    > I have a web application that is contained in a war file. I have a
    > requirement to generate an xml file ( will be an rss field ), that can
    > be accessible at a given url within my web application. This file
    > could be quite big, so I can't just generate it on the fly per
    > request. Nor can I cache it in session data.
    >
    > I'd prefer to deploy my application in war, rather than exploded-war
    > format ( portability being a large concern.... ), however given I need
    > to generate this xml file and save it in a directory of my web-app
    > root, I think my only option is to revert to exploded war use.
    >
    > Is there any way of programatically creating/updating a file within
    > say, the my-app war from a servlet in the war itself?
    >
    > My alternative strategies are
    >
    > 1) saving the xml to the database ( something that the purist in me
    > hates the idea of ).
    > 2) pushing the file to another server.


    How about

    (3) Generate it at application startup or on the first request, and
    store it in the temp directory provided to you by the servlet container.
    Create a servlet, mapped to the designated URL, that delivers the data.

    That is completely independant of deployment format, does not depend on
    another server, and should be as efficient as you can hope for given
    your requirements.


    John Bollinger
    John C. Bollinger, Nov 4, 2003
    #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. Java Job
    Replies:
    1
    Views:
    4,184
    Mike Schilling
    Aug 5, 2004
  2. Josh McCulloch
    Replies:
    1
    Views:
    992
    Sudsy
    Aug 19, 2004
  3. Manoj Nair
    Replies:
    0
    Views:
    621
    Manoj Nair
    Jun 8, 2004
  4. SenthilVel
    Replies:
    0
    Views:
    116
    SenthilVel
    Mar 8, 2007
  5. Replies:
    4
    Views:
    415
    Arne Vajhøj
    Apr 26, 2013
Loading...

Share This Page