What to do to export classes from a JAR file from one Eclipse RCP plugin and import them into another one?

  1. If you want, create a folder for the JAR library in your plugin. You could also place the JAR files at the root of the plugin, but of you also have source attachments, this would clutter that directory quite a lot.
  2. Right click on the target directory in Eclipse Package Explorer and select “Import …”, then “General > File System”. Do not select “General > Archive File”, as this would unpack the JAR file when importing. Then select your JAR file and import it.
  3. Right click on the JAR file and select “Build Path > Add to Build Path”.
    Right click on the JAR file and select “Build Path > Configure Build Path …”, and there “Order and Export”. In that list, create a tick in the line for your JAR file. Without it, it is not contributed to dependent Java projects; this is a Java mechanis, we’ll have to deal with the Eclipse RCP mechanisms additionally now.
  4. Open the build.properties file of the project that now contains the JAR file, with the Build Properties Editor of Eclipse. That is, double-click that file in the Eclipse Package Explorer. In the “Binary Build” section, create a tick for your JAR file, and in the “Source Build” section, create a tick for its source attachment, if any.
  5. Now, the Eclipse-specific stuff. Or better, OSGi specific. Open the MANIFEST.MF file of the project that now contains the JAR file, with the Plug-in Manifest Editor of Eclipse. That is, double-click that file in the Eclipse Package Explorer. Here, in the “Classpath” section, click “Add” and add your JAR file. And in the “Runtime” section, click “Add” and add the packages exported by your class file. The latter step is not necessary in the rare case that your JAR file contributes classes to packages that are already exported (as happens with PrivilegedAccessor, contributing to the junit.extensions of JUnit).
  6. Open the MANIFEST.MF file of the project that shall import the JAR file, with the Plug-in Manifest Editor of Eclipse. In the “Dependencies” tab, in “Required Plug-ins”, add the plug-in that holds the JAR.
  7. Now you’re able to use classes from the JAR file in import statements.

Posted

in

,

by

Tags:

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.