Using shared libraries with Eclipse RCP
This post describes an easy – but little known way – to use native libraries (.dlls) with Eclipse RCP.
In my current work, I’m shipping an RCP application that interacts directly with hardware connected to the user’s machine. These interactions are done through drivers, written in C, that are available in binary form as shared libraries.
The use of shared libraries introduces a few problems:
- In order to load and be accessible from Java, the shared libraries must be on the PATH (windows) / LD_LIBRARY_PATH (unix). The user should not need to manually configure these environment variables. An excellent way to solve this, is to put the .dlls into the same directory as the application’s executable (the eclipse launcher).
- However: the .dlls are platform specific (32-bit vs 64-bit / Windows vs OS X vs Linux). This means that the right version of the library must be placed next to each executable.
The Product Export Wizard / PDE-Build, allows us to do this with minimal effort, as described below:
- I’m assuming you have a feature-based .product configuration file for your application.
- In your feature, create a folder for each platform that you support. The example below supports three platforms: os-x-64-bit, win-32-bit, win-64-bit.
- Place the appropriate binary files in each folder.
- Edit the build.properties file, adding a: root.os.ws.arch=foldername entry for each platform. For example, the entry ‘win32.win32.x86=win32.x86’ means if you are on a 32-bit windows, place the contents of the folder ‘win32.x86’ next to the application’s executable.
- If needed, add permissions entries to the build.properties file. These entries can be used to set the unix permissions for individual files, when needed. For example, the entry ‘root.macosx.cocoa.x86_64.permissions.755=library.so’ sets the permissions of ’library.so’ file to ‘755’.
Done — the .zip files created by the ‘Product Export Wizard’ (and PDE Build) now have the correct libraries, with permissions, next to the executable.
For more details, refer to “Adding Files to the Root of a Build” in the Eclipse Help.
If you made it this far, follow me on twitter, Elias.