views:

79

answers:

5

Can I programmatically use an Eclipse plugin in my java code (so that it is independent from eclipse)?

A: 

You should take a look in your eclipse directory. In the plugins folder you'll find a lot of .jar files. Sure, you could use these as dependencies in your project.

xor_eq
It's more complicate than just using these jar files, because they may have a lot of dependencies. Have a look on my answer below to get more details.
Manuel Selva
Oh, I didn't say that it was easy to do so, the question was clearly about if it was possible, and it is, as you state in your own answer as well.
xor_eq
A: 

Yes, sure, you just need to care deploy plugin's jar files with you project properly.

Artem Barger
A: 

Well designed plugins are split into UI and "core" parts. You would probably want to grab just the core component. And you may well need to provide an OSGi framework to properly load and activate the plugin too - depending on how complex it is.

As others have also mentioned, don't forget the dependencies.

dty
+1  A: 

Yes you can if:

  • The plugin you want to use doesn't have any external dependencies => it's just a library plugin

  • The plugin you want to use and ALL it's dependencies are in your classpath

No in all other cases. Because many plugins use at least the core concepts of OSGI/Equinox (have an activator) it will be quite hard to use them in a standalone java app.

For example, SWT can be used outside eclipse.

Manuel Selva
A: 

Eclipse plugins are OSGi bundles.

OSGi bundles are JAR files that have extra info in META-INF that declares exports and imports. They sometimes make calls to OSGi APIs.

Many Eclipse plugins depend on other Eclipse-specific plugins.

If you use OSGi in your environment, you can easily reuse those plugins that have no Eclipse dependencies. If your application is not OSGi, you can only easily reuse those that avoid the direct use of OSGi APIs.

bmargulies