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.
Bundle-NativeCode: 
 nativelib/Linux/i686-unknown-linux-gnu/librxtxParallel.so;
 nativelib/Linux/i686-unknown-linux-gnu/librxtxSerial.so;
 osname=Linux; processor=x86,
 
 nativelib/Linux/ia64-unknown-linux-gnu/librxtxSerial.so;
 osname=Linux; processor=ia64,
 
 nativelib/Linux/x86_64-unknown-linux-gnu/librxtxSerial.so;
 osname=Linux; processor=x86-64,
 
  
 nativelib/Mac_OS_X/librxtxSerial.jnilib;
 osname=Mac OS X; processor=x86; processor=PowerPC; processor=x86-64,
 
 
 nativelib/Solaris/sparc-solaris/sparc32-sun-solaris2.8/librxtxSerial-2.1-7.so;
 nativelib/Solaris/sparc-solaris/sparc32-sun-solaris2.8/librxtxSerial.so;
 osname=Solaris; processor=Sparc,
 
 nativelib/Solaris/sparc-solaris/sparc64-sun-solaris2.8/librxtxSerial-2.1-7.so;
 nativelib/Solaris/sparc-solaris/sparc64-sun-solaris2.8/librxtxSerial.so;
 osname=Solaris; processor=Sparc64,
 
 
 nativelib/Windows/i368-mingw32/rxtxParallel.dll;
 nativelib/Windows/i368-mingw32/rxtxSerial.dll;
 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