Jayesh A Lalwani wrote:
a) You can use reflection to load the concrete class
you need to define an interfac which is the contract between your main code and the deployed jar. The jar contains a concrete implementation. The class name of the concrete class is in a configuration file somewhere. You can use reflection to load the class, instantiate the object, and use it via the interface
...
c) OSGi
OSGi provides a lot of services that allow you to do this. But, it's a bigger learning curve.
Thanks a lot, Jayesh! I use 1'st approach and load with reflection right now, and it works quite well. But I'm moving towards OSGi, because it looks like I can create OSGI-related code without intervention to application code in the jar, and gain all benefits of OSGi, but it's really a lot of thinks to learn. As you mentioned the configuration file should be located somewhere, right now I put in the same Factory method jar as properties file, but if I will add new concrete factory with a new jar I will need to modify this properties file in Factory method jar, which is not very convenient.
Where can I store these config files if I use OSGi? I've heard it is possible to define <key,value> pairs in console (Equinox, Felix), but not sure how.