• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

how can i get path of class file in an app.?

 
Ranch Hand
Posts: 93
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
can we get the path of class file programaticaly in an application? i belive getCodeBase() helps in applet.
thanks,
sanjeev.
 
Ranch Hand
Posts: 1209
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
did u try
getResource() in class Class?
actually there is one in ClassLoader class as well.
URl u = string.class.getResource("test.class");
String path = new File(u.getFile()).getAbsolutePath();
 
sanjeev mehra
Ranch Hand
Posts: 93
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am going to try it. Thanks for the reply. Thanks a lot.
Sanjeev.
 
Ranch Hand
Posts: 107
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
you can use this code to see from where the class is being loaded.
MyClass.class.getProtectionDomain().getCodeSource().getLocation()
hope this helps
 
author
Posts: 3252
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by sanjeev mehra:
can we get the path of class file programaticaly in an application?

The above suggestions should work, but I'm curious as to why you would need this. If it is to impose some restrictions, best use the normal Java security features. If you need to load some additional resources like graphics or HTML documentation, put them in the jar(s) and use ClassLoader.getResource() or ClassLoader.getResourceAsStream(). (You can obtain a suitable classloader using, for example, DataInterface.class.getClassLoader()).
- Peter
 
Ranch Hand
Posts: 69
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i am also using this and the reason is when server will be loaded i will provide exact loction of db.db file to user and ask him if he want to change it.
on client side if user choose localmode, same situation.
regards,
bhuvan.
reply
    Bookmark Topic Watch Topic
  • New Topic