• Post Reply Bookmark Topic Watch Topic
  • New Topic

Plugins in my Java app...!! help Needed...!!  RSS feed

 
Parth Bhatt
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi !!
I am working on a project where i need to provide plugin support. i.e. i plan to design a desktop application which reads for plugins at start up from a specific directory where each plugin is a ".jar" file.

i have been thru a post on this forum that nicely illustrated the intricacies involved in reading the jar file(so i'm thru with that). My problem is, precicely, designing the application such that the code inside the plugin is executed as and when needed...!!

Can somebody either
a> Elaborate upon the way such an application should be designed or
b> suggest some site that explains "writing java applications that provide plugin support"

Thanks in advance...!!
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Create an interface called "Plugin", or some such. The person writing a plugin has to implement the Plugin interface. In their jar file, they should include some indication of which class implements Plugin -- for example using a line in the MANIFEST.MF file, or a file named "plugin.properties", or however you want to do it. You read this information, load the named class from the jar file, create an instance, and cast it to Plugin. Then you call the methods of the Plugin interface, as appropriate.
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There are many ways you could cause a plugin to execute.

Maybe a plugin replaces functionality on an existing menu item like File/Save to add a save to repository along with save to disk. Then you'll replace the default implementation of the FileSave interface with the plugin you found as Ernest described.

Or maybe your plugin adds a whole new menu item. Then your plugin description will have to include a description of how to set up the menu, according to rules you write into your application. Many Eclipse plugins do this, eg adding a choice to the right-click menu in the source code editor.

I have plugins for a page generator I wrote that works on user input. The user writes ${page size} in the page editor to display the size of the page and I try to load a class called PageMacro. I have a bunch of default macros in the page generator application, but it's easy to add custom macros in custom jars. Note that these are not "registered" or discovered as Ernest described; they just have to be in the classpath.

So the answer, as always, is "it depends." Does one of those models fit your vision for your application? Did you have something else in mind?
[ March 01, 2006: Message edited by: Stan James ]
 
Parth Bhatt
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think i hav got a solution 4 now...!!

I shall try designing such an interface n a plugin.properties file...!! i believe this will solve my problem...!!

i fully agree to your "it depends" funda stan ... Thats very true...!! As i said i am yet to start designing my app, i shall have to do a bit of primary coding, then i shall be able to derive the complete picture...!! But this much of info should be enough i believe.

thanks a lot Ernest & stan, your response has made my work Ezzzz...!!
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!