This week's book giveaway is in the OO, Patterns, UML and Refactoring forum.
We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes How to get all classes present in a package? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Beginning Java
Bookmark "How to get all classes present in a package?" Watch "How to get all classes present in a package?" New topic
Author

How to get all classes present in a package?

sneha ulhe
Ranch Hand

Joined: May 15, 2012
Posts: 52

How can we get list of all classes present in any package,is there any method for that?


Sneha
[OCJP 6]
Jeff Verdegan
Bartender

Joined: Jan 03, 2004
Posts: 6109
    
    6

It's not possible in the general case, but for certain limited cases you can do it. Get the current ClassLoader, and if it's a URLClassLoader, then get its URLs, turn them into URIs, turn those into Files (if they are file URIs), and then list the files in the File object corresponding to the directory representing your package.

The question though is why? What are you trying to accomplish that you think you need to do this?
 
Have you checked out Aspose?
 
subject: How to get all classes present in a package?
 
jQuery in Action, 3rd edition