views:

23

answers:

1

Simple problem, I need to write a sitemap to my web root directory so that it is accessible as so:

http://mysite.com/sitemap.xml

I want the code to look like:

File f = new File( someMethodToGetWebRootDirectory() );

But I don't know what should be in that method

A: 

Will something along the lines of:

File classesDir = new File(YourServlet.class.getProtectionDomain()
    .getCodeSource().getLocation().getPath().replaceAll('/', File.separator));
File rootDir = classesDir.getParentFile().getParentFile();

work?

binil
There might not be a solution to this that works across application servers. One can imagine a server which never expands a war file onto disk.
binil