Now that I think more about it... if I understand your question
correctly, I don't think being able to change what you're describing as
the 'Geronimo default path' will make a difference. What I mean is
this...
In Plain Old Tomcat, when you deploy a war by copying it into the
$TOMCAT_HOME/deploy directory, it explodes it into
$TOMCAT_HOME/deploy/warname, right? So, to access your properties
file, relative to the 'default path' of your server (Tomcat in this
case), the path to the properties file is
'/deploy/warname/myfile.properties'.
In Geronimo (1.1), if you deploy a war via the command line deployer
tool, it will stuff the exploded version somewhere under the
$GERONIMO_HOME/repository. If you didn't explicitly specify, then it
will go to $GERONIMO_HOME/repository/default/warname. So, in this
case, the path relative to the 'default path' is not what it was in
Tomcat, it is '/repository/default/warname/myfile.properties'.
Now, if you're saying you can edit the absolute path to the properties
file somewhere that your app will pick it up, why not just leave the
'/bin' directory on the 'default path' as you describe it, but put a
'..' at the beginning of the absolute path? Haven't tried it recently,
so am not sure if the Java API's for dealing with Files and Paths are
smart enough to handle the '..'
Am I misunderstanding you?
Bryan Noll wrote:
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 = ""
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;
}
|