Monday, September 17, 2007

A simple plugin framework in Java

As part of my hobby project, I thought of coming up with some sort of a plug-in mechanism. Though I have worked in a "plug and play"-like J2EE project, I have never done a desktop application with plug-in nature.
I like the way plug-ins work in eclipse. Just extract your plug-ins in to a specific folder. So, my application also would have a similar plug-in mechanism.
Following is the way I have implemented the plug-in manager:

Get to plugins directory
For each file in plugins directory
If file ends with ".jar"
See if there is a plugin-manifest.xml inside the jar
If found read the XML and get data about the Plugin
Save plugin data to a list/map for future use
Add the jar to current classpath as plugin may be used.
End if
End if
End for

No comments: