Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #31698
| Path | csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!1.eu.feeder.erje.net!eternal-september.org!feeder.eternal-september.org!mx02.eternal-september.org!.POSTED!not-for-mail |
|---|---|
| From | Eric Sosman <esosman@comcast-dot-net.invalid> |
| Newsgroups | comp.lang.java.programmer |
| Subject | Re: get a list of classes at runtime |
| Date | Wed, 13 May 2015 11:23:01 -0400 |
| Organization | A noiseless patient Spider |
| Lines | 41 |
| Message-ID | <mivq6r$ptd$1@dont-email.me> (permalink) |
| References | <mivd25$2m28$1@ariadne.rz.tu-clausthal.de> <mivlo4$83v$1@dont-email.me> <mivi58$2n3g$1@ariadne.rz.tu-clausthal.de> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=windows-1252; format=flowed |
| Content-Transfer-Encoding | 7bit |
| Injection-Date | Wed, 13 May 2015 15:22:03 +0000 (UTC) |
| Injection-Info | mx02.eternal-september.org; posting-host="858a9d65d95f4ea4d355bd116aa2cdbf"; logging-data="26541"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX184r+6jJaXDG43DsWXE+EI/" |
| User-Agent | Mozilla/5.0 (Windows NT 6.1; WOW64; rv:31.0) Gecko/20100101 Thunderbird/31.6.0 |
| In-Reply-To | <mivi58$2n3g$1@ariadne.rz.tu-clausthal.de> |
| Cancel-Lock | sha1:98AYkMO1Vqfbe0GpfCdoUGYJjCI= |
| Xref | csiph.com comp.lang.java.programmer:31698 |
Show key headers only | View raw
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().
--
esosman@comcast-dot-net.invalid
"Don't be afraid of work. Make work afraid of you." -- TLM
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