Getting a Web Accessible Directory in Spring-MVC/Java
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 = n开发者_运维技巧ew File( someMethodToGetWebRootDirectory() );
But I don't know what should be in that method
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?
精彩评论