Wrapping RXTX in an Eclipse Plugin

From Rxtx

Jump to: navigation, search

This would be done to simplify the development of [Eclipse] Plug-ins and RCP applications that use rxtx.

Wrapping this code in a plug-in gives the following advantages:

  • A link to the javadoc can be associated with the jar, so users of the newly created plug-in can easily pull up the javadoc inside eclipse.
  • The native libraries can all be associated with this jar, so the newly created plug-in can support multiple targets OS & CPU architectures.
  • Associating the javadoc and grabbing the right native library only has to be done once for all projects using rxtx.
  • You don't have to modify the JRE of any machine. Eclipse will package the jar and corresponding native libraries in your RCP/plug-in application. Upon startup, it will select the appropriate .dll or .so file to unpack and add the .jar file to the classpath.

Please note that I've used my RXTX plugin for Mac OS X (ppc) and Windows (x86) only. I haven't tested this configuration on the other targets setup in this tutorial.

Procedure (Using Eclipse 3.3 - Europa)

  • In the New Project Wizard, select Plug-in Development->Plug-in from existing JAR archives and click Next.
  • Use the Add External... button to add the downloaded RXTXcomm.jar file to include in the plugin and click Next.
  • Fill in the Plug-in Project Properties and click Finish. Make sure "Unzip the JAR archives into the project" is unchecked or you will not be able to associate the javadoc. Otherwise, you can do what you want. Here's an example:
    • Project Name: rxtx plugin
    • Plug-in ID: org.rxtx
    • Plug-in Version: (insert the version of rxtx that your are wrapping)
    • Plug-in Name: rxtx Plug-in
    • Plug-in Provider: rxtx.org
  • You will now see your new plugin project in the Package Explorer. Notice that if you open the manifest, META-INF->MANIFEST.MF, in the editor and switch to the Runtime tab, you will find gnu.io in the Exported Packages (and also RXTXcomm.jar in the Classpath). This is what lets you use the java libraries when you include this new plugin in your dependency list.
  • Create a new folder in your project called nativelib (or whatever you want).
  • Import all the native libraries (.dll, .so, etc.) from your rxtx download under this folder.
  • Add the following OSGI directive to the Manifest to tell the OSGI framework how to select the appropriate native libs at startup (MANIFEST.MF tab of the MANIFEST editor).
    • Make sure to have single spaces in the following locations: After the Bundle-Nativecode: directive, on all line continuations, and on all blank lines.
    • Make sure to adjust the folder structure to your folder structure.
    • Make sure to change the file names to the appropriate ones (i.e. the files that have the version number in them might change).
    • Make sure to adjust the native lib references to the ones that you actually have.
    • Please note that I'm not sure about the OSGI processor name, Sparc64.
 osname=Linux; processor=x86,
 osname=Linux; processor=ia64,
 osname=Linux; processor=x86-64,
 osname=Mac OS X; processor=x86; processor=PowerPC; processor=x86-64,
 osname=Solaris; processor=Sparc,
 osname=Solaris; processor=Sparc64,
 osname=Win32; processor=x86
  • Right click on the .jar file (Referenced Libraries->RXTXComm.jar and select Properties
  • Select Javadoc Location and enter the link to this wiki's javadoc (i.e. http://users.frii.com/jarvi/rxtx/doc/). Use the Validate... button to make sure you have it right (Make sure index.html is not at the end of your link). Click Apply and then OK.

You're done! Now you can use this plugin in your other projects as long as it remains open in your project directory. If you like, you can use the Export Wizard in the Overview tab of the manifest editor to distribute this. You can even create a feature project and include this plug-in if you want to distribute via an eclipse update site. The feature project is nice in any case from a usability standpoint because it allows you to specify all of the target OS's and architectures (CPU's) this supports.

Personal tools