Not exactly what you're asking for, but couldn't you do this....
String home = servletConfig..getServletContext().getRealPath("/");
or... check out the attached file.
Fran Varin wrote:
We have a web application that reads some Java Properties files when it
initializes. In order to avoid having to code a physical directory path to
the Properties files we would like to use a relative path.
Also, we would like to keep the Properties files packaged within the WAR
file. When Geronimo comes up its default path ends up being something like:
c:\apache\geronimo-tomcat-j2ee-1\geronimo-1.0\bin\ (Based on the
windows install directory)
We have been successful in accomplishing the above using Tomcat since Tomcat
allows the default directory to be configured. Is there a similar
configuration for Geronimo?
--
View this message in context:
http://www.nabble.com/How+to+change+the+default+directory-t1670804.html#a4528855
Sent from the Apache Geronimo - Users forum at Nabble.com.
/**
* Returns the resource defined by the 'resource' parameter as a
* java.io.File object. It is expected that the 'resource' parameter is a
* path (either to a directory or file) relative to the classpath.
*
* If the 'resource' path provided is not relative to the classpath, the
* return value will be a non-null java.io.File object whose 'exists()'
* method returns false. It is the responsibility of the caller to check
* the value of 'exists()', as this method makes no guarantee to return
* a File object that exists.
*
* @param caller - Class object to use in the call to:
* <code> caller.getResource(resource) </code>
* You should expect a resource you want to use to be loaded by the same
* ClassLoader that loaded the classes in your artifact (jar, war, ear, etc.)
*
* @param resource
* @return java.io.File - non-null, may or may not exist, depending on
* 'resource' input param
*/
public static final File getClasspathResource(Class caller, String resource) {
File returnFile = null;
try {
URL url = caller.getResource(resource);
if (url != null) {
String urlFile = getFileSystemPathFromUrlPath(url.getFile());
if (url != null) {
returnFile = new File(urlFile);
if (returnFile == null || !returnFile.exists()) {
returnFile = new File(resource);
}
} else {
returnFile = new File(resource);
}
}
} catch (Exception ignore) {
}
return returnFile;
}
/**
* Replaces the http url encoding of a space (%20) with an actual space,
* so that if you try to do something like this:
* <code> File f = new File(filePathString) </code>
* it will be able to locate the file on the file system.
*
* @see http://www.blooberry.com/indexdot/html/topics/urlencoding.htm
* @see http://www.ietf.org/rfc/rfc2396.txt
*
* @param percent20InsteadOfSpacesString
* @return
*/
public static final String getFileSystemPathFromUrlPath(String
percent20InsteadOfSpacesSt
String goodString = percent20InsteadOfSpacesString.replaceAll("%20", "
");
return goodString;
}