Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / April 2005

Tip: Looking for answers? Try searching our database.

Using Reflection to get all Classes?

Thread view: 
Julian - 29 Apr 2005 17:33 GMT
Hallo,

I'm currently writing a Java-Application that is supposed to offer a
sort of Class Browser (similar to the Smalltalk Class Browser).

I understood the necessarity of Reflections. It's easy to get a Class
with a known name (like: Class c = Class.forName(knownName);)
But I would like to create a Class Browser that shows all classes that
are available in the system. Is this possible? If it is, how?

Thank you very much in advance!

Julian Wissel
Tor Iver Wilhelmsen - 29 Apr 2005 17:56 GMT
> But I would like to create a Class Browser that shows all classes that
> are available in the system. Is this possible? If it is, how?

You need to navigate System.getProperty("java.class.path") and the
bootclasspath. Look in every jar, directory etc. - recursively - and
analyze .class files. Remember to "convert" nested classes (they have
a $ in their names).
John C. Bollinger - 29 Apr 2005 18:10 GMT
>>But I would like to create a Class Browser that shows all classes that
>>are available in the system. Is this possible? If it is, how?
[quoted text clipped - 3 lines]
> analyze .class files. Remember to "convert" nested classes (they have
> a $ in their names).

And you must recognize that the classes you discover this way are not
the only ones that an application running on the system might be able to
load.  An application may include any number of its own classes or
external libraries that come from locations not on the default
classpath.  You might not find all these even if you were to run your
class browser from within the application in question.  You certainly
will never find classes that an application might load over a network,
or from a database, or those that an application might synthesize at
runtime.

In general, it is impossible to find "all classes available in the
system", but if you narrow the scope (to classes available via the class
browser's own classpath, for instance) then you can achieve the goal.

Signature

John Bollinger
jobollin@indiana.edu

Thomas Schodt - 30 Apr 2005 03:10 GMT
> I'm currently writing a Java-Application that is supposed to offer a
> sort of Class Browser (similar to the Smalltalk Class Browser).
[quoted text clipped - 3 lines]
> But I would like to create a Class Browser that shows all classes that
> are available in the system. Is this possible? If it is, how?

Using reflection it is possible to get a list of all *loaded* classes
from the classloader.
Not nice, but it is possible.


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.