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.
# 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
# 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");