How can I find out where the class files are installed in a
programmtic way?
Thanks,
Menlo
Oliver Wong - 12 Apr 2007 18:30 GMT
> How can I find out where the class files are installed in a
> programmtic way?
Classes might not come from files: they may be loaded from the
network, or dynamically generated.
- Oliver
Tom Hawtin - 12 Apr 2007 21:22 GMT
> How can I find out where the class files are installed in a
> programmtic way?
clazz.getProtectionDomain().getCodeSource().getLocation()
You might not get meaningful information from this.
Tom Hawtin
Andrew Thompson - 13 Apr 2007 02:22 GMT
>How can I find out where the class files are installed in a
>programmtic way?
Why (do you think you need to know)? What ability
are you attempting to bring to the end user, by identifying
where the class files reside?

Signature
Andrew Thompson
http://www.athompson.info/andrew/
Arne Vajhøj - 16 Apr 2007 02:42 GMT
> How can I find out where the class files are installed in a
> programmtic way?
Try something like:
private String getPath(Class cls) {
String cn = cls.getName();
String rn = cn.replace('.', '/') + ".class";
String path =
getClass().getClassLoader().getResource(rn).getPath();
int ix = path.indexOf("!");
if(ix >= 0) {
return path.substring(0, ix);
} else {
return path;
}
}
Arne