Finding all of the classes in a package

J

Jerald

I'm trying to build a flexible plugin structure and it seems like a good
way would be to include each plugin class in a package.

That assumes, of course, that there is some way to discover what classes
exist in the package. So far I cannot find anything in the ClassLoader,
Class or Package specs that would obviously do that. Any methods I can
find require me to know the name of the class I want to load.

Am I barking up the wrong tree? Is there another good way to go about this?

Thank you
Rich
 
C

Chris Smith

Jerald said:
I'm trying to build a flexible plugin structure and it seems like a good
way would be to include each plugin class in a package.

Certainly plugins can be placed into packages. It sounds, though, as if
you're trying to be too restrictive on the way plugins are written.
Enforcing a rule of one package per plugin class is forced and
unnatural, not to mention completely unnecessary.
That assumes, of course, that there is some way to discover what classes
exist in the package. So far I cannot find anything in the ClassLoader,
Class or Package specs that would obviously do that. Any methods I can
find require me to know the name of the class I want to load.

There is no such thing. It is a fundamental concept of Java class
loading that you must first know the name of the class you want, and
then load the class.
Am I barking up the wrong tree? Is there another good way to go about this?

Yes, you are barking up the wrong tree. The right way to do this
depends on exactly what you want. Ideally, plugins would be distributed
as JAR files, and you'd read some fixed thing in the JAR file (perhaps
the manifest) to discover the name of the plugin class. That seems to
be the best way overall.

--
www.designacourse.com
The Easiest Way To Train Anyone... Anywhere.

Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation
 
T

Thomas Weidenfeller

Jerald said:
That assumes, of course, that there is some way to discover what classes
exist in the package.

No, you can not. This is discussed several times a month :-( Go read an
archive of the group.

/Thomas
 
J

Jerald

Thank you. Actually I found the FAQs but didn't find the archive. Could
you please point me at it?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,754
Messages
2,569,527
Members
45,000
Latest member
MurrayKeync

Latest Threads

Top