get classes from package

S

Stefan Haun

Hi,

I want to fetch all classes defined by a specified package (so I only have
to setup a package to let my controller load the classes), but I cannot find
a way to do this.

Can anyone help?


Greetings,
Stefan
 
C

Chris Smith

Stefan said:
I want to fetch all classes defined by a specified package (so I only have
to setup a package to let my controller load the classes), but I cannot find
a way to do this.

There is no way to do this.

A package in Java is open; classes may become available at any time
during the execution of the application, and do not become available
until the first time someone attempts to use them. Because of this,
there's no way to list all of the classes that are available.

This may sound strange if your conception of a package is a directory or
JAR file on disk (and, in fact, it's quite possible to get a list of
class files in a JAR or directory)... but Java's classes may instead
come from a web server which may not provide a file listing service at
all (this is fairly common in the case of applets), or even from a
custom classloader that generates code on the fly from the class name,
so that there are actually an inifinite number of classes to be loaded!
Can anyone help?

The common solution to this problem is to ask for a configuration
resource of a fixed name, and list the available classes in that
configuration resource. A developer would then package their classes
and their appropriate configuration resources as a single JAR file and
distribute it. This technique is used in so large a number of existing
Java software systems that you'd be quite unlikely to confuse anyone
with the request. Systems that use this include the Java SDK API
classes for at least SE and EE versions (I'm not that familiar with ME).
For a good example, look for some documentation on writing providers for
JavaMail.

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

Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation
 

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,764
Messages
2,569,565
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top