Best practice for referencing an external module in a Java project

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

  • Implementing a specific interface in the main project
  • Packed in uni-jar (along with any dependencies)
  • Contains some readable meta information (e.g. module name).

My main project should be able to load at runtime (for example, using its own class loader) any of these external modules. My question is: what is the best way to register these modules with the main project (I would rather save this vanilla Java rather than using third-party frameworks / libraries for this isolated problem)?

My current solution is to save a single .properties file in the main project with key = name, value = class | delimiter | man-readable-name (or coordinate two .properties files to avoid separator parsing). At run time, the main project is loaded into the .properties file and uses whatever records it finds to control the class loader.

It feels like hockey for me. Is there a better way to do this?

+5
source share
3 answers

The standard approach in Java is to define a service provider. Cm

http://java.sun.com/j2se/1.4.2/docs/guide/jar/jar.html#Service%20Provider

+4
source

XML . "my-module-data.xml".

path *: my-module-data.xml( FrontController) FrontController , , :)

google Spring -OSGI doco .

0

@ZZ Coder...

, JDK, JDK 6 ServiceLoader. Netbeans Lookup API.

. , API . NetBeans - API (, , ).

Of course, it would be a mistake not to mention the dominant, more "heavyweight" standards of EJB, Spring, and OSGi.

0
source

All Articles