Results 1 to 3 of 3
  1. #1
    Join Date
    Jan 2011
    Posts
    3
    Rep Power
    0

    Default Plugin discovery

    Hi all,

    I've been looking around on the net for a tutorial on how to create a plugin discovery system for a java program.

    I am trying to follow the example found at What is Java Reflection? | JAVA Developer's Journal

    I have a simple class which implements my plugin interface.

    Java Code:
    public class Main implements IXactPlugin
    {
        String name = "Plugin1";
    
        public static void main(String[] args)
        {
            System.out.println("Here");
            Main moo = new Main();
        }
    
        public Main()
        {
            process();
            System.out.println(getName());
            System.out.println(methods()[0].getName());
        }
        public void process()
        {
            System.out.println("Process");
        }
    
        public String getName()
        {
            return name;
        }
    
        public Method[] methods()
        {
            Method m[] = null;
            try
            {
    
                Class c = Class.forName(this.getClass().getName());
                m = c.getDeclaredMethods();
            }
            catch (Throwable e)
            {
               System.err.println(e);
            }
            return m;
    
        }
    }
    I then want to load that plugin and be able to call those methods having dynamically loaded that class in another program.

    Here is the code I have for the plugin loader
    Java Code:
    File folder = new File("C:/Users/Ash/Documents/NetBeansProjects/PluginFramework/plugins");
            File[] listOfFiles = folder.listFiles();
            
            for ( int i = 0; i < plugInNames.length; i++ ) 
            {
                MyApplicationPlugIn plugIn = (MyApplicationPlugIn)Class.classFor( plugInNames[i] );
            }
    Problem I am having is the line
    Java Code:
    MyApplicationPlugIn plugIn = (MyApplicationPlugIn)Class.classFor( plugInNames[i] );
    It cant find the classFor method.

    Any help would be greatly appreciated.

    Kind Regards

    Ash

  2. #2
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,574
    Blog Entries
    7
    Rep Power
    21

    Default

    Quote Originally Posted by ashleypursglove View Post
    Problem I am having is the line
    Java Code:
    MyApplicationPlugIn plugIn = (MyApplicationPlugIn)Class.classFor( plugInNames[i] );
    It cant find the classFor method.
    The name of that (static) method is Class.forName(String className). It loads the class for you (if not already loaded) but throws an Exception if it can't find the class. Read the API documentation for the Class class.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  3. #3
    Join Date
    Jan 2011
    Posts
    3
    Rep Power
    0

    Default

    Thanks for the reply Jos.

    I thought this might be the case.

    I've changed the line as follows

    Java Code:
    IXactPlugin plugIn = (IXactPlugin)Class.forName( "Main" );
    But now get the compilation error

    inconvertible types
    required: pluginframework.IXactPlugin
    found: java.lang.Class<capture#2 of ?>

    Kind Regards

    Ash

Similar Threads

  1. Replies: 0
    Last Post: 12-16-2010, 10:14 AM
  2. Discovery of peer in p2p network
    By dogukan in forum Networking
    Replies: 1
    Last Post: 04-19-2010, 03:55 PM
  3. Trying to send UDP discovery packet
    By JohnST in forum New To Java
    Replies: 1
    Last Post: 12-26-2009, 07:32 PM
  4. Bible-Discovery 2.1
    By JavaBean in forum Java Software
    Replies: 0
    Last Post: 10-25-2007, 04:19 PM
  5. AnyEdit Plugin For Eclipse Plugin
    By JavaForums in forum Eclipse
    Replies: 0
    Last Post: 05-18-2007, 12:28 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •