Search code examples
eclipseencapsulationmodularity

How to reuse code in different Eclipse plugins independently


If I have 2 different Eclipse plugins with similar functionality (e.g. they both implement an extension point or a service of a third plugin), how can I easily reuse the same code in both plugins without making one depend on the other?

Example: Have both plugins share the exact same Activator.java.

Alternatives I already thought about:

  • Create another (base) plugin to contain the shared code and make the other 2 plugins depend on that base plugin. Fits the general Eclipse modularity concepts, but leads to functionality spread over multiple plugins and to having plugins without any sensible functionality encapsulated in them.
  • Have a library project in Eclipse and reference that as source or as JAR in the 2 plugin projects. This way I avoid creating "helper" plugins, but having a library project refer to classes from the Eclipse plugin runtime somehow also doesn't seem right.

Solution

  • The standard way to do this is to create the third plugin. Generally if you are using plugin development, it's best to use that for everything (don't create library projects). This way you get all of the benefits of plugin development for everything.