Re: Using Reflection to get all Classes?



Tor Iver Wilhelmsen wrote:

julianwissel@xxxxxx (Julian) writes:


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).

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.

--
John Bollinger
jobollin@xxxxxxxxxxx
.



Relevant Pages

  • Re: javac vs Makefile problem ...
    ... any Java class even if the Java source did not change. ... javac uses the directory as specified with -d to store compiled .class files, however, it does not automatically search in that directory when looking for type information. ... Instead, it uses the classpath, and, when defined, the sourcepath to search for classes and source code. ... Some time ago I considered to write a special make for Java, which allows to specify cyclic dependencies, and does the grouping into sets of cyclic dependent source code internally. ...
    (comp.lang.java.programmer)
  • Re: Help with "main" error
    ... > I use the command line as follows: ... > The full error message is as follows: ... > I thought it may be the CLASSPATH, but all my class files are located in the ...
    (comp.lang.java)
  • Re: Help with "main" error
    ... > I use the command line as follows: ... > The full error message is as follows: ... > I thought it may be the CLASSPATH, but all my class files are located in the ...
    (comp.lang.java.help)
  • Re: Find All public static main methods
    ... actually load in a JVM, meaning they are in the classpath or you have a classloader that can load them. ... ASM over BCEL; on the whole I think they're probably right -- not that I've ... ASM's performance is blindingly fast compared to BCEL, and Jen takes full advantage of that, too (hardly impacting performance at all), so it's the best of both worlds. ...
    (comp.lang.java.programmer)
  • Re: Accessing Class Method
    ... you will inevitably be loading class files (requiring) where you'd ... loads any required resource without one class knowing whether or not another ... , so for now, require_once is a one-line, quick means to load ...
    (comp.lang.php)