Win a copy of AWS Security this week in the Cloud/Virtualization forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • salvin francis
  • fred rosenberger

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

 
Ranch Hand
Posts: 93
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • 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
  • 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
  • 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
  • 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.
 
Forget Steve. Look at this tiny ad:
Devious Experiments for a Truly Passive Greenhouse!
https://www.kickstarter.com/projects/paulwheaton/greenhouse-1
    Bookmark Topic Watch Topic
  • New Topic