Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Getting the location of class file

 
Kashif Iqbal Khan
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is there anyway I could find the path of the class file that is being executed.
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 7023
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic