jQuery in Action, 3rd edition
The moose likes Beginning Java and the fly likes Getting the location of class file Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Getting the location of class file" Watch "Getting the location of class file" New topic

Getting the location of class file

Kashif Iqbal Khan

Joined: Dec 22, 2001
Posts: 13
Is there anyway I could find the path of the class file that is being executed.

Kashif I. Khan
David O'Meara

Joined: Mar 06, 2001
Posts: 13459

In code, turn the fully qualified class name into a file path, then use getResource() from the ClassLoader and print out the URL it returns. If you keep it as a URL, it will even show the location in JARs.
eg to find com.javaranch.davo.MyClass

That may need debugging, I wrote it off the top of my head.
Dirk Schreckmann

Joined: Dec 10, 2001
Posts: 7023
If you're just trying to figure out the working directory of some Java application, then the "user.dir" System property might do the trick.

[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
I agree. Here's the link: http://aspose.com/file-tools
subject: Getting the location of class file
It's not a secret anymore!