get classes from package

Discussion in 'Java' started by Stefan Haun, Jul 30, 2004.

  1. Stefan Haun

    Stefan Haun Guest

    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
     
    Stefan Haun, Jul 30, 2004
    #1
    1. Advertising

  2. Stefan Haun

    Chris Smith Guest

    Stefan Haun wrote:
    > 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
     
    Chris Smith, Jul 30, 2004
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Carfield Yim
    Replies:
    1
    Views:
    1,521
    Andrew Thompson
    May 31, 2004
  2. Christian Bongiorno
    Replies:
    5
    Views:
    560
    Chris Uppal
    Aug 30, 2004
  3. Chameleon

    get package classes

    Chameleon, Apr 27, 2005, in forum: Java
    Replies:
    1
    Views:
    506
    Tor Iver Wilhelmsen
    Apr 27, 2005
  4. Tomasso

    Get classes from package

    Tomasso, May 23, 2006, in forum: Java
    Replies:
    9
    Views:
    6,181
    Furious George
    May 25, 2006
  5. aeonsun
    Replies:
    4
    Views:
    591
    Paul Cager
    Jul 27, 2006
Loading...

Share This Page