Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #31700
| Newsgroups | comp.lang.java.programmer |
|---|---|
| Date | 2015-05-13 08:59 -0700 |
| References | <mivd25$2m28$1@ariadne.rz.tu-clausthal.de> <mivlo4$83v$1@dont-email.me> |
| Message-ID | <4b9ec70b-28f1-488f-9945-ec6ebf8ebda8@googlegroups.com> (permalink) |
| Subject | Re: get a list of classes at runtime |
| From | e.d.programmer@gmail.com |
On Wednesday, May 13, 2015 at 10:07:19 AM UTC-4, Eric Sosman wrote: > On 5/13/2015 8:47 AM, Philipp Kraus wrote: > > Hello, > > > > > > I would like to get a list of all loadable classes, because I create an > > UI which should be list on the user input, which classes are existst > > e.g. the user types ABC and I will get the full class name with > > packages, e.g. package1.subpackage.ABC and package2.ABC > > "All loadable classes" is a potentially infinite set, since a class > loader might look almost anywhere to find a class -- it might even > synthesize a class by filling a byte[] array with bytecodes and then > loading it. But perhaps your goal is not quite so ambitious ... > > > I have taken a look into https://github.com/ronmamo/reflections but I > > don't find a call to filter all class names. How I can get the full > > class name list during runtime (all my classes are stored within a Jar > > file and the search should be also add the Java base classes e.g. String) > > 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. > > -- > esosman@comcast-dot-net.invalid > "Don't be afraid of work. Make work afraid of you." -- TLM To find the rt.jar your IDE would just have to specify where the rt.jar is. Normally to build a project in Eclipse you add "JRE System Library" to the build path. You'll see that as a folder in the Package Explorer. You can expand that folder. I don't know if Oracle/Sun publishes a list of which jars to include or where they get it but my Eclipse project using Java 8 update 40 has 18 jars listed there.
Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
get a list of classes at runtime Philipp Kraus <philipp.kraus@flashpixx.de> - 2015-05-13 14:47 +0200
Re: get a list of classes at runtime Eric Sosman <esosman@comcast-dot-net.invalid> - 2015-05-13 10:06 -0400
Re: get a list of classes at runtime Philipp Kraus <philipp.kraus@flashpixx.de> - 2015-05-13 16:14 +0200
Re: get a list of classes at runtime Eric Sosman <esosman@comcast-dot-net.invalid> - 2015-05-13 11:23 -0400
Re: get a list of classes at runtime Arne Vajhøj <arne@vajhoej.dk> - 2015-05-17 19:29 -0400
Re: get a list of classes at runtime Joshua Cranmer 🐧 <Pidgeot18@verizon.invalid> - 2015-05-13 22:15 -0500
Re: get a list of classes at runtime e.d.programmer@gmail.com - 2015-05-13 08:59 -0700
Re: get a list of classes at runtime Eric Sosman <esosman@comcast-dot-net.invalid> - 2015-05-13 16:05 -0400
Re: get a list of classes at runtime Martin Gregorie <martin@address-in-sig.invalid> - 2015-05-13 22:43 +0000
Re: get a list of classes at runtime Joerg Meier <joergmmeier@arcor.de> - 2015-05-13 16:20 +0200
Re: get a list of classes at runtime j4n bur53 <janburse@fastmail.fm> - 2015-05-13 17:47 +0200
Re: get a list of classes at runtime Arne Vajhøj <arne@vajhoej.dk> - 2015-05-17 19:09 -0400
csiph-web