Re: get a list of classes at runtime

Posted by Eric ... on 13. May 2015

On 5/13/2015 10:14 AM, Philipp Kraus wrote:




On 2015-05-13 14:06:53 +0000, Eric Sosman said:




On 5/13/2015 8:47 AM, Philipp Kraus wrote:



 AFAIK, the JVM has no record of potentially loadable classes that


have not been loaded (there are probably some special-case exceptions
like String and Class and Throwable, but they'll all have been loaded
well before your code runs). If I'm right, it means the only way you
can find the not-yet-loaded classes is to rummage through the JAR's (or
other sources) for yourself. You presumably know where to find your
own JAR's and things; I believe all "base classes" reside in rt.jar.
I don't know of a convenient way to find "the" rt.jar that your JVM
happens to be using; the best I can think of is to read the java.home
System property and search from there. (Or from sun.boot.class.path,
but I'm not certain that's a property all JVM's will define.)



 Anyhow: Once you've found the JAR's, you'll read their directories,


do a little reformatting, and filter as you please.




I think so, but how do IDEs like IntelliJ or Eclipse this call? If I
write into the code editor
something a dialog is show, which lists all possibility classes.
So imho I need to run over the Jar, create an index of all class files
and use a pattern structure to
match the names.




 That's what I would do.  Note that a JAR will have directory entries


for all its classes, including nested classes, private classes, and
package-private classes. You can filter out the nested classes by their
funny-looking names, but if you also want to filter based on access I
can think of only two ways:



 - Read the class file (the format is described in the JVM spec).

- Load the class (use the three-argument form of Class.forName()
if you don't want to initialize it) and use getModifiers().




[email protected]
"Don't be afraid of work. Make work afraid of you." -- TLM


07. Apr 2015: Re: Return of the Applets? by Leif ...

07. Apr 2015: Re: Return of the Applets? by Jerry...

07. Apr 2015: Re: presentable Java features and programs by Jeff ...

07. Apr 2015: Re: Return of the Applets? by Jerry...

06. Apr 2015: Re: Return of the Applets? by Marti...

06. Apr 2015: presentable Java features and programs by ram a...

06. Apr 2015: Re: Return of the Applets? by Joshu...

06. Apr 2015: Re: presentable Java features and programs by Eric ...

06. Apr 2015: Re: Return of the Applets? by Kevin...

06. Apr 2015: Re: presentable Java features and programs by Arne ...

06. Apr 2015: Re: presentable Java features and programs by Jeff ...

06. Apr 2015: Re: presentable Java features and programs by Arne ...

06. Apr 2015: Re: presentable Java features and programs by Jeff ...

06. Apr 2015: Re: presentable Java features and programs by Eric ...

06. Apr 2015: Re: presentable Java features and programs by Jeff ...

06. Apr 2015: Re: Return of the Applets? by Jerry...

06. Apr 2015: Re: Return of the Applets? by Jerry...

06. Apr 2015: Re: presentable Java features and programs by Jerry...

06. Apr 2015: Re: Return of the Applets? by Joshu...

06. Apr 2015: Re: Return of the Applets? by Jerry...

06. Apr 2015: Re: Return of the Applets? by Joshu...

06. Apr 2015: Re: Return of the Applets? by Jan B...

06. Apr 2015: Re: Return of the Applets? by Jan B...

06. Apr 2015: Re: Return of the Applets? by Jan B...

06. Apr 2015: Re: Return of the Applets? by Jerry...

06. Apr 2015: Re: Any good book/website with samples how to run Java in web applications? by Marti...

06. Apr 2015: Re: Return of the Applets? by Joshu...

06. Apr 2015: Re: Return of the Applets? by Joshu...

06. Apr 2015: Re: Return of the Applets? by Luuk ...

06. Apr 2015: Re: Return of the Applets? by Richa...

06. Apr 2015: Re: Return of the Applets? by Jeff ...

06. Apr 2015: Re: Return of the Applets? by Jeff ...

06. Apr 2015: Re: What are the professional development kits for Java by david...

05. Apr 2015: Re: Return of the Applets? by Arne ...

05. Apr 2015: Re: Return of the Applets? by Arne ...

05. Apr 2015: Re: Any good book/website with samples how to run Java in web applications? by Arne ...

05. Apr 2015: Re: Return of the Applets? by Jerry...

05. Apr 2015: Re: Return of the Applets? by Arne ...

05. Apr 2015: Re: Return of the Applets? by Jerry...

05. Apr 2015: Re: Any good book/website with samples how to run Java in web applications? by dffdf...

05. Apr 2015: Re: Return of the Applets? by ram a...

05. Apr 2015: Re: Return of the Applets? by Arne ...

05. Apr 2015: Re: Any good book/website with samples how to run Java in web applications? by Arne ...

05. Apr 2015: Re: Return of the Applets? by Jerry...

05. Apr 2015: Re: Return of the Applets? by Arne ...

05. Apr 2015: Re: Return of the Applets? by Jerry...

05. Apr 2015: Re: Return of the Applets? by Arne ...

05. Apr 2015: Re: Any good book/website with samples how to run Java in web applications? by dffdf...

05. Apr 2015: Re: Return of the Applets? by Jerry...

05. Apr 2015: Re: Integer.parseInt() and whitespace? by Jukka...

05. Apr 2015: Re: Any good book/website with samples how to run Java in web applications? by Arne ...

05. Apr 2015: Re: Integer.parseInt() and whitespace? by Arne ...

05. Apr 2015: Re: Return of the Applets? by Jeff ...

05. Apr 2015: Re: What are the professional development kits for Java by Arne ...

05. Apr 2015: Re: Return of the Applets? by Jerry...

05. Apr 2015: Return of the Applets? by ram a...

05. Apr 2015: Re: Integer.parseInt() and whitespace? by ram a...

04. Apr 2015: Any good book/website with samples how to run Java in web applications? by dffdf...

04. Apr 2015: Re: What are the professional development kits for Java by Arne ...

04. Apr 2015: Integer.parseInt() and whitespace? by galt_...

04. Apr 2015: What are the professional development kits for Java by dffdf...

04. Apr 2015: Re: Client and ... ? by Jeff ...

04. Apr 2015: Muhammad's Sword by BV BV...

04. Apr 2015: Re: how to write this simple program? by Lew l...

04. Apr 2015: Re: Client and ... ? by Lew l...

03. Apr 2015: Re: Simple if-exercises by v_bor...

03. Apr 2015: Re: Simple if-exercises by Marti...

03. Apr 2015: Re: Simple if-exercises by Jeff ...

03. Apr 2015: Re: Simple if-exercises by Marti...

03. Apr 2015: Re: Simple if-exercises by v_bor...

03. Apr 2015: Re: Simple if-exercises by Eric ...

03. Apr 2015: Re: Simple if-exercises by Marti...

03. Apr 2015: Re: Simple if-exercises by Eric ...

03. Apr 2015: Re: Simple if-exercises by v_bor...

03. Apr 2015: Get Access to the Professional Videos of Java at ITeLearn by charl...

02. Apr 2015: Re: Simple if-exercises by Gene ...

02. Apr 2015: Re: Simple if-exercises by Jerry...

02. Apr 2015: Re: Simple if-exercises by Marti...

02. Apr 2015: Re: Simple if-exercises by Jeff ...

02. Apr 2015: Re: Simple if-exercises by Jeff ...

02. Apr 2015: Re: Simple if-exercises by Eric ...

02. Apr 2015: Simple if-exercises by ram a...

01. Apr 2015: Re: .parallelStream() by Sebas...

01. Apr 2015: .parallelStream() by ram a...

01. Apr 2015: Client and ... ? by ram a...

01. Apr 2015: Re: Is it legal to backport code from JDK8 to JDK6? by Haddo...

01. Apr 2015: Re: .parallelStream() by Eric ...

01. Apr 2015: Re: Client and ... ? by Jeff ...

31. Mar 2015: Re: Is it legal to backport code from JDK8 to JDK6? by Sebas...

31. Mar 2015: Re: Draw bolder(ly)? by Marti...

31. Mar 2015: Re: Is it legal to backport code from JDK8 to JDK6? by Fredr...

31. Mar 2015: Re: Is it legal to backport code from JDK8 to JDK6? by Fredr...

31. Mar 2015: Re: Draw bolder(ly)? by Jeff ...

31. Mar 2015: Re: Draw bolder(ly)? by Jeff ...

31. Mar 2015: Re: Draw bolder(ly)? by Knute...

31. Mar 2015: Re: Draw bolder(ly)? by ram a...

30. Mar 2015: For all algorithm enthusiasts by Algo-...

30. Mar 2015: Re: Draw bolder(ly)? by Jeff ...

30. Mar 2015: Re: Is it legal to backport code from JDK8 to JDK6? by Sebas...

30. Mar 2015: Re: Draw bolder(ly)? by Jeff ...