generated file location in tomcat

Hi, I hava a fairly simple JSF application which at a certain point creates an XML file.

I have created the file no problem using the DocumnetBuilder but am unsure as to how to specify where the file will be created. the code that actualy created the file is:

OutputFormat format = new OutputFormat(dom);

format.setIndenting(true);

XMLSerializer serializer = new XMLSerializer(new FileOutputStream new File("report.xml")), format);

I thought that this would place the file in the root of my applications folder in webapps but instead it places it in tomcats bin directory.

How do I specify the root of my own application?

Thanks in advance.

[691 byte] By [MacGiolcagha] at [2007-11-26 20:19:31]
# 1
I hope this helps FacesContext = FacesContext.getCurrentInstance(); ExternalContext external = cntext.getExternalContext(); context.setResponseStream("WEB=INF/foo.bar");
ferric4a at 2007-7-10 0:43:34 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2
Sorry Let try this again FacesContext context = FacesContext.getCurrenInstance(); ExternalContext external = context.getExternalContext(); external.setResourceAsStream("/WEB-INF/foo.bar");
ferric4a at 2007-7-10 0:43:34 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 3

Sorry I missed your reply, thanks.

your line of code:

external.setResourceAsStream("/WEB-INF/foo.bar");

is not working for me, I am told there is no setResourceAsStream for external.

Here is the code I have

OutputFormat format = new OutputFormat(dom);

format.setIndenting(true);

XMLSerializer serializer = new XMLSerializer(new FileOutputStream(

new File("report.xml")), format);

serializer.serialize(dom);

This works fine for me, but it is writing the report.xml file to the bin directory of tomcat.

I would like to put into my apps own directory in webapps. I know that this is probably baby stuff but I am pretty new to web application dev.

Cheers

Message was edited by:

MacGiolcagh

MacGiolcagha at 2007-7-10 0:43:34 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 4

> How do I specify the root of my own application?

I don't understand exactly which scope you're talking about. So here are two options:

String applicationPath = System.getProperty("user.dir");

or

String webcontainerPath = ((ServletContext) FacesContext.getCurrentInstance().getExternalContext().getContext()).getRealPath("/");

Then define the path in File object:

File xmlFile = new File(yourPath, "report.xml");

BalusCa at 2007-7-10 0:43:34 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 5
String webcontainerPath = ((ServletContext) FacesContext.getCurrentInstance().getExternalContext().getContext()).getRealPath("/");that's the one I was after! thanks very much.
MacGiolcagha at 2007-7-10 0:43:34 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...