Creating new files in an existing deployed war file.

B

Ben Jessel

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
 
B

Ben_

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 ? :))).
 
J

John C. Bollinger

Ben said:
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
(e-mail address removed)
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,819
Latest member
masterdaster

Latest Threads

Top