Best Practice For Referencing an External Module In a Java Project

Posted by Greg Harman on Stack Overflow See other posts from Stack Overflow or by Greg Harman
Published on 2010-05-10T16:50:43Z Indexed on 2010/05/10 16:54 UTC
Read the original article Hit count: 287

Filed under:
|
|
|

I have a Java project that expects external modules to be registered with it. These modules:

  • Implement a particular interface in the main project
  • Are packaged into a uni-jar (along with any dependencies)
  • Contain some human-readable meta-information (like the module name).

My main project needs to be able to load at runtime (e.g. using its own classloader) any of these external modules. My question is: what's the best way of registering these modules with the main project (I'd prefer to keep this vanilla Java, and not use any third-party frameworks/libraries for this isolated issue)?

My current solution is to keep a single .properties file in the main project with key=name, value=classhuman-readable-name (or coordinate two .properties files in order to avoid the delimiter parsing). At runtime, the main project loads in the .properties file and uses any entries it finds to drive the classloader.

This feels hokey to me. Is there a better way to this?

© Stack Overflow or respective owner

Related posts about java

Related posts about module