<p>I intend to develop a system that is entirely based on modules. The system base should have support for finding out about plugins, starting them up and being able to provide ways for those modules to communicate. Ideally, one should be able to put in new modules and yank out unused modules at will, and modules should be able to use each other's funcionality if it is available.</p>

<p>This system should be used as a basis for simulation systems where a lot of stuff happens in different modules, and other modules might want to do something based on that.</p>

<p>The system I intend to develop is going to be in Java. The way I see it, I intend to have a folder with a subfolder for each module that includes a XML that describes the module with information such as name, maybe which events it might raise, stuff like that. I suppose I might need to write a custom ClassLoader to work this stuff out.</p>

<p>The thing is, I don't know if my idea actually holds any water and, of course, I intend on building a working prototype. However, I never worked on a truly modular system before, and I'm not really sure what is the best way to take on this problem.</p>

<p>Where should I start? Are there common problems and pitfalls that are found while developing this kind of system? How do I make the modules talk with each other while maintaining isolation (i.e, you remove a module and another module that was using it stays sane)? Are there any guides, specifications or articles I can read that could give me some ideas on where to start? It would be better if they were based on Java, but this is not a requirement, as what I'm looking for right now are ideas, not code.</p>

<p>Any feedback is appreciated.</p>

[{'answer_id': 78031, 'author': 'Joe Skora', 'author_id': 14057, 'author_profile': 'https://Stackoverflow.com/users/14057', 'pm_score': 2, 'selected': False, 'text': '<p>Without getting into great detail, you should be looking at <a href="http://springframework.org/" rel="nofollow noreferrer">Spring</a> and a familiarization with OSGI or the Eclipse RCP frameworks will also give you some fundamental concepts you will need to keep in mind.</p>\n'}, {'answer_id': 78047, 'author': 'Patrick Desjardins', 'author_id': 13913, 'author_profile': 'https://Stackoverflow.com/users/13913', 'pm_score': 1, 'selected': False, 'text': '<p>They are many way to do it but something simple can be by using Reflection. You write in your XML file name of file (that would be a class in reallity). You can than check what type is it and create it back with reflection. The class could have a common Interface that will let you find if the external file/class is really one of your module. Here is some information about <a href="http://java.sun.com/docs/books/tutorial/reflect/index.html" rel="nofollow noreferrer">Reflexion</a>.</p>\n\n<p>You can also use a precoded framework like this SourceForge one<a href="http://sourceforge.net/projects/javasps/" rel="nofollow noreferrer">link text</a> that will give you a first good step to create module/plugin.</p>\n'}, {'answer_id': 78063, 'author': 'Alexander Klimetschek', 'author_id': 2709, 'author_profile': 'https://Stackoverflow.com/users/2709', 'pm_score': 4, 'selected': True, 'text': '<p>You should definitely look at <a href="http://www2.osgi.org/Specifications/HomePage" rel="noreferrer">OSGi</a>. It aims at being <em>the</em> component/plugin mechanism for Java. It allows you to modularize your code (in so-called bundles) and update bundles at runtime. You can also completely hide implementation packages from unwanted access by other bundles, eg. only provide the API.</p>\n\n<p>Eclipse was the first major open-source project to implement and use OSGi, but they didn\'t fully leverage it (no plugin installations/updates without restarts). If you start from scratch though, it will give you a very good framework for a plugin system.</p>\n\n<p><a href="http://felix.apache.org" rel="noreferrer">Apache Felix</a> is a complete open-source implementation (and there are others, such as <a href="http://www.eclipse.org/equinox/" rel="noreferrer">Eclipse Equinox</a>).</p>\n'}, {'answer_id': 78247, 'author': 'John Meagher', 'author_id': 3535, 'author_profile': 'https://Stackoverflow.com/users/3535', 'pm_score': 2, 'selected': False, 'text': '<p>Another option is the <a href="http://java.sun.com/javase/6/docs/api/java/util/ServiceLoader.html" rel="nofollow noreferrer">ServiceLoader</a> added in Java 1.6.  </p>\n'}]
['https://Stackoverflow.com/questions/78004', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/-1/']