f



Creating new files in an existing deployed war file.

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
0
ben.jessel (41)
11/3/2003 1:26:08 PM
comp.lang.java.programmer 52714 articles. 1 followers. Post Follow

2 Replies
650 Views

Similar Articles

[PageSpeed] 59

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


0
Ben_
11/3/2003 1:45:19 PM
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
jobollin@indiana.edu

0
jobollin (1557)
11/4/2003 3:26:14 PM
Reply: