*
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


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Getting the location of class file" Watch "Getting the location of class file" New topic
Author

Getting the location of class file

Kashif Iqbal Khan
Greenhorn

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
Rancher

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
Sheriff

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]
 
 
subject: Getting the location of class file