Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

get class location 1

Status
Not open for further replies.

jemminger

Programmer
Jun 25, 2001
3,453
US
is there any way to determine where in the file system a class is?

for example, if my class Foo.class is in
c:/foo/bar/classes/Foo.class

is there some way for Foo to know about this path?




=========================================================
-jeff
try { succeed(); } catch(E) { tryAgain(); } finally { rtfm(); }
 
Hi Jeff,

Try this :

Code:
String path = this.getClass().getProtectionDomain().getCodeSource().getLocation().toString();
System.out.println(path);

Now this works with a simple standalone class, but I'm sure its failed on classes contained within a webapp or jar ... give it a go and see if it works for you :)

--------------------------------------------------
Free Database Connection Pooling Software
 
sedj, thanks! looks like that'll work


=========================================================
-jeff
try { succeed(); } catch(E) { tryAgain(); } finally { rtfm(); }
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top