rich client 2.0

Using RCP for Marketing CD-ROMs


21. May 2007
Tom Seidel @ 10:28

If you are attending a fair there are a lots of exhibitors providing you with a CD-ROM containing a small program for company- or product-marketing. Sometimes the exhibitor also wants to distribute documents, PDF-Documents for example, in a nice wrapper. So why not use the Eclipse RCP to build such an application? - The following article will describe how to embed a Derby database and configure your product in a way that will make it possible to execute it from a CD-ROM.

Embedded Derby Database

On the Derby-Website you'll find an eclipse-plugin which contains the Derby database (org.apache.derby.core). To integrate the database download the plugin and set a dependency in your plugin.xml. To set up a connection pool you can copy the source-code from the Derby ui-plugin to initialize your connection. Additionally you have to integrate the commons-pool and commons-dbcp.

JAVA:
  1. public class DatabaseUtil {
  2.  
  3.  /**
  4.   * Datasource to use for connection.
  5.   */
  6.  private static PerUserPoolDataSource datasource;
  7.  
  8.   public static final String URL = "myDataBase/"; //$NON-NLS-1$
  9.    
  10.  /**
  11.   * Initializes database and creates datasource instance for it.
  12.   */
  13.  private static void initDatasource () {
  14.   EmbeddedConnectionPoolDataSource connectionPoolDatasource;
  15.   connectionPoolDatasource = new EmbeddedConnectionPoolDataSource();
  16.   connectionPoolDatasource.setDatabaseName(URL);
  17.   connectionPoolDatasource.setCreateDatabase("create")//$NON-NLS-1$
  18.        
  19.   datasource = new PerUserPoolDataSource();
  20.   datasource.setDefaultMaxActive(-1);
  21.   // important for cd distribution
  22.   datasource.setDefaultReadOnly(true);
  23.   datasource.setConnectionPoolDataSource(connectionPoolDatasource);
  24.   datasource.setDefaultAutoCommit(false);
  25.  
  26.  }
  27.    
  28.     /**
  29.      * @return the datasource
  30.      */
  31.     public static PerUserPoolDataSource getDatasource() {
  32.         if (datasource == null) {
  33.             initDatasource();
  34.         }
  35.         return datasource;
  36.     }
  37. }

Redirecting Derby Files

The next step is to set up Derby's working files to a directory on hard disc. It is recommended to create a folder in the user's home directory for writing Logs and Error-Stream. You have to set the following System properties:

derby.system.home
derby.storage.tempDirectory
derby.stream.error.file

Setting Eclipse's Workspace

Eclipse always needs a workspace directory to save all kinds of data, e.g dialog-settings, preferences, save-states, etc. On default eclipse creates the workspace directory in the eclipse-root folder, which is not possible if you want to deliver your application via CD-Rom. Therefore, you have to set the following parameters in your RCP's config.ini:

osgi.configuration.area=@user.home/.myProduct
osgi.instance.area.default=@user.home/.myProduct/workspace
data=@user.home/.myProduct/workspace

The rest of the product branding process is the same like as regular RCPs. Don't forget to bundle a JRE.

Conclusion

I have already had the opportunity to implement such an application (ca. 20k copies). It was a PDF Browser with a simple search. The integration of Derby was very easy and the handling does not differ from other systems. The execution of statements on a CD-Rom located database for simple search-queries and the start of the Eclipse-Framework are quite fast enough and you still have the possibility to save dialog-settings and preferences. It is a cool alternative to built marketing-orientated applications and shows the wide field of application of the Eclipse Rich Client Platform. Ah, and don't forget the autorun.inf ;)

2 Comments »

  1. Hi Tom.
    Really I must thank you for the amount of innovative ideas behind all your work.
    I came across this site when I was doing some search of event handling between two views,and your code helpmed me a lot to learn.
    thanks again
    Shreedhara

    Comment by Shreedhar — 18. June 2007 @ 06:56

  2. Thanks for infor - works fine - I have only one more question.
    If I have application starting from cdrom and I want to be able to upgrade some features in future and install them for ex. ‘@user.home/.myProduct/install’ what do I do?
    Apparently product don’t want turn on automatic updates if it is placed on cdrom. It always try to install updates in directory where previous version is placed.

    Comment by PaweÅ‚ Witek — 24. June 2007 @ 22:08

RSS feed for comments on this post. TrackBack URI

Leave a comment

Powered by WordPress