Finding all of the classes in a package

Discussion in 'Java' started by Jerald, Feb 17, 2005.

  1. Jerald

    Jerald Guest

    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
     
    Jerald, Feb 17, 2005
    #1
    1. Advertising

  2. Jerald

    Chris Smith Guest

    Jerald <> wrote:
    > 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
     
    Chris Smith, Feb 17, 2005
    #2
    1. Advertising

  3. Jerald wrote:
    > 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

    --
    The comp.lang.java.gui FAQ:
    ftp://ftp.cs.uu.nl/pub/NEWS.ANSWERS/computer-lang/java/gui/faq
     
    Thomas Weidenfeller, Feb 17, 2005
    #3
  4. Jerald

    Jerald Guest

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



    Thomas Weidenfeller wrote:
    > Jerald wrote:
    >
    >> 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
    >
     
    Jerald, Feb 18, 2005
    #4
  5. Jerald

    Tilman Bohn Guest

    In message <>,
    Jerald wrote on Thu, 17 Feb 2005 19:53:58 -0500:

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


    groups.google.com? ;-)

    --
    Cheers, Tilman

    `Boy, life takes a long time to live...' -- Steven Wright
     
    Tilman Bohn, Feb 18, 2005
    #5
    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. guava
    Replies:
    1
    Views:
    2,712
    Joseph Millar
    Aug 8, 2003
  2. Wolfgang Heintz

    Finding all Classes of a Package

    Wolfgang Heintz, Oct 2, 2003, in forum: Java
    Replies:
    7
    Views:
    4,266
    Wolfgang Heintz
    Oct 6, 2003
  3. Carfield Yim
    Replies:
    1
    Views:
    1,486
    Andrew Thompson
    May 31, 2004
  4. Christian Bongiorno
    Replies:
    5
    Views:
    555
    Chris Uppal
    Aug 30, 2004
  5. Jason Teagle

    List All Classes In A Package

    Jason Teagle, Oct 6, 2004, in forum: Java
    Replies:
    12
    Views:
    23,274
Loading...

Share This Page