An alternative: the servletContext.getResource() method -> that
works on weblogic(10) and tomcat(6)
"return an URL to the resource relative to the current context
root"
if you change
ServletContainer to use getResource (ONLY if
getRealPath returns null)
private String[] getPaths(String classpath) {
if (classpath == null) {
if (context.getRealPath("/") != null){
return new String[] {
context.getRealPath
("/WEB-INF/classes"),
context.getRealPath("/WEB-INF/lib")
};
}else{ // try access to Resource URI
try{
return new String[] {
context.getResource("/WEB-INF/classes").toString(),
context.getResource("/WEB-INF/lib").toString()
};
}catch(MalformedURLException exc){
return new String[0];
}
}
} else {
.... // same code
and ClasspathResourceConfig as:
private void
init(String[] paths) {
File[] roots = new File[paths.length];
for (int i = 0; i< paths.length; i++) {
if (
paths[i].contains(":")) // allows access to
path that start with some protocol
roots[i] = new File(
URI.create(paths[i]));
else
roots[i] = new File(paths[i]);
}
... // same code
Tomcat vs. Weblogic on servletContext.getResource()
- in weblogic, returns the "real" path to the tmp deployment
directory (file:/......)
- in tomcat, returns "jndi" path
(jndi:localhost/rest/WEB-INF/classes) -< note that currently code
use getRealPath() if not returns null !
Paul, Do you think that getResource() is better alternative than
getRealPath()?
thank you
Paul Sandoz wrote:
Jose
Antonio Illescas del Olmo wrote:
I don't think for Servlet we can use the
current approach as the default zero-config mechanism :-(
Then, I use the init-params in weblogic environments...
+1
I am thinking that should be the default option as it appears the most
interoperable.
Paul.