Showing posts with label plugin. Show all posts
Showing posts with label plugin. Show all posts

2007-01-09

Adding a third party JAR to your Eclipse plugin

I often get the question "How to add a third party JAR-file to my Eclipse plugin". It is not that tricky, but neither that obvious. Two solutions has been posted on the Eclipse newslists, but it can be quite hard to find it as the sheer number of posts is overhelming.

Here is two ways of doing it:
1. Turn the JAR-file(s) into plugin(s)
This is probably the simplest solution, but maybe not always achieving the desired granularity though. "Use New" -> "Project" -> "Plug-in Development" -> "Plug-in from existing JAR Archive". That will turn the JAR-file into a single JAR-plugin. Check that all required packages are re-exported.

2. Include the JAR-file(s) in the plugin in question:

  • Use the "Import" -> "File System" to import the JAR-file(s) into your plugin project. E.g. '/lib' directory

  • Then use "Add..." to add the JAR-file(s) to the classpath section of the Manifest/plugin.xml runtime tab.

  • Press "New..." to add "." library back to the the classpath (without quotes).

  • Check that the binary build exports the new JAR-file(s) on the Build tab.

  • Press save, important for the changes to come through.

  • Select the project in question in the package explorer view, right click and select "PDE Tools" -> "Update classpath". This will add the newly added JAR-file(s) to the project´s classpath.
When you are in the process of exporting the plugin make shure you do not package the plugin as "individual JAR archives", Eclipse cannot load JARs from within JARs, yet.