File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes Getting the location of class file Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Beginning Java
Reply 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]
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: Getting the location of class file
 
Similar Threads
ClassNotFoundException
Java Petstore 2.0
Incompatible magic value
URLClassLoader problem
Compiling servlet [was: HTTP Status 404 - Servlet Login is not available]