IntelliJ IDEA How-To

Using IntelliJ IDEA for Eclipse RCP development

Introduction

This article describes how to migrate applications developed using the Eclipse Rich Client Platform (RCP) to IntelliJ IDEA. Because of the Eclipse architecture, such applications are implemented as plugins to the Eclipse platform. However, this does not mean you absolutely must use the Eclipse Java Development Toolkit (itself a plugin to the Eclipse platform). So if you like SWT and RCP, but prefer IntelliJ IDEA as a Java IDE, you can migrate any SWT/RCP application to IntelliJ IDEA. The process is a bit involved (this article will guide you step-by-step), but once completed, you’ll be able to work on your SWT/RCP applications in your preferred IDE, taking advantage of all the productivity features you know and love in IntelliJ IDEA.

Prerequisites

The reader should be acquainted with the Eclipse platform architecture.

We recommend having a separate installation of the Eclipse to run your RCP application. If your application is developed as Eclipse product, the Eclipse Rich Client Platform can be used instead of using Eclipse SDK. You can download the Eclipse RCP 3.2 here. Please note that we use Eclipse RCP installation as a working directory for the RCP application, so we recommend you to make the backup of the platform.

Please also read Migrating applications from Eclipse 3.x to IntelliJ IDEA that describes basic terminology difference between IntelliJ IDEA and Eclipse and the process of creating IntelliJ IDEA projects and modules.

Migrating RCP applications to IntelliJ IDEA

To demonstrate the migration process and possible mappings of files and folders to the IntelliJ IDEA project structure, we considered the Eclipse plug-in project based on "RCP Mail Template" that was created using Eclipse PDE. This template generates a standalone RCP application, complete with views, menu and toolbar actions, keybindings and a product definition . To get the similar test application create new Plug-in project in Eclipse, choosing the RCP Mail Template as template, provide org.example.rcp.mail as project name, and then create Product Configuration for your plug-in to make this application deployable as Eclipse product.
We consider a simple application structure that contains only one project without any external dependencies.

  1. In IntelliJ IDEA, create a new single-module or multi-module project. The project file can be located in your Eclipse workspace.
  2. Add a new Java module and name it Mail. Set the module content root point to the location of your RCP application, so that all the files that are generated by Eclipse (such as plugin.xml or manifest.mf) will be automatically added to the module. Note that you will not be able to work with the same project from Eclipse after migration is complete, so if you still need your Eclipse project you should create the backup copy. For example, see the screenshot below.
    Add Module
  3. Click Next, and IntelliJ IDEA will discover the source files of your application. Accept the suggested source folder.
  4. Set the module's output directory to point to <Eclipse RCP installation folder>\plugins\<your application name>. IntelliJ IDEA will automatically create this directory to use it as a compilation output, so Eclipse RCP platform will find your plugin during start up.
    Module Output Path
  5. Create a new project library (Settings | Project Structure), name it Eclipse RCP and add to this library all Eclipse JARs that you need for your SWT and RCP development (in most cases, you simply need to add all files from <eclipse RCP installation folder>\plugins). If you use other Eclipse plugins that are not included into the Eclipse RCP distribution package, you can create separate libraries for them, or simply add them to the same Eclipse RCP library.
  6. You need to add one more JAR file to your Eclipse RCP library. This is the startup.jar file that you can find in the RCP installation root folder. This file contains the main class for launching your application.
  7. Add the newly created Eclipse RCP library to the classpath of the Mail module.
    Module Mail
    Now you can edit your RCP application in IntelliJ IDEA, use code completion and navigation features, see JavaDoc, etc. The next thing is to set up for running and debugging this application from IntelliJ IDEA.
  8. For running and debugging the application, we use JARs from the Eclipse RCP installation, while all the plugin configuration files are located in the workspace. Now we need to make IntelliJ IDEA to create the necessary plugin structure in the RCP installation folder (you can take a look at the sample project structure at the Final project structure figure). For this purpose, we need to mark all the necessary files as module sources.
    • Create a new directory within the Mail module and name it resources.
    • Use the Move refactoring (F6) to move the following files and folders to the resources directory:
      • META-INF folder
      • plugin.properties file
      • plugin.xml file
      • Other files that are used by your RCP application as resources and not located under the source folder (*.xml, *.ini, *.properties, *.product, *.html, *.gif etc. files).
        For example, for our org.example.rcp.mail project we should move the following items to the resources folder: icons and META-INF folders, plugin.xml, plugin.properties, splash.bmp, product_lg.gif files.
    • Mark the resources directory as the Mail module source (Settings | Project Structure)
      Module Mail Source
  9. If you are developing the application that is Eclipse product and try to run it with pure Eclipse RCP you should create two files (config.ini and .eclipseproduct) and put it to the Eclipse RCP installation to make your application start. You don't need these files if you are using Eclipse SDK as a target platform and don't need your application to be Eclipse product.

    Put the config.ini file to the configuration folder of Eclipse RCP installation, and the .eclipseproduct file (that is optional ) – to the installation root folder.

    Note:

    the best way to create these files is to export your application from Eclipse as Eclipse Product - Eclipse generates them and after that you can find them in the application folder.

    If you plan to modify the product configuration (product id property, required budles etc.) and want the properly changed config.ini and .eclipseproduct files to be deployed to the target platform by IDEA, and use pure Eclipse RCP as target platform, you may follow the instructions below. Elsewhere skip this step and go to p.10.

    According to Eclipse platform architecture, these files should be located on the same level as the plugins folder. To satisfy this requirement:

    • Create a new Java module and name it Descriptor (you can accept the default location and source folder).
    • Set up the Descriptor module output directory to point to the Eclipse RCP installation folder.
      Module Descriptor
    • Make sure that in the Settings | Compiler the Clear output directory on rebuild checkbox is not selected. Otherwise you can accidentally remove the RCP installation.
    • Make the Mail module dependent on this new Descriptor module. For this purpose, add the Descriptor module to the classpath of the Mail module.
      Mail Descriptor
    • Create the .eclipseproduct file in the source directory of the Descriptor module.
      The file should contain application version, name, and ID (use product id value from *.product file of your application here). For example:
          version=1.0.0
          name=RCP Product
          id=org.example.rcp.mail.product
          
      Note:

      If you have exported the application as product from Eclipse, you can find the autogenerated file in the exported application folder.

    • Create the configuration folder within the source folder of the Descriptor module, and create the config.ini file in it.
      The file should contain the following system properties:

      • osgi.bundles
      • osgi.bundles.defaultStartLevel
      • eclipse.product
      • osgi.splashPath

      For example, for our sample mail application, for Eclipse RCP 3.2, this file may look as follows:

           osgi.splashPath=platform:/base/plugins/org.example.rcp.mail
           eclipse.product=org.example.rcp.mail.product
           osgi.bundles=org.eclipse.equinox.common@2:start,
           org.eclipse.core.runtime@start,com.ibm.icu,
           org.eclipse.core.commands,org.eclipse.core.contenttype,
           org.eclipse.core.expressions,org.eclipse.core.jobs,
           org.eclipse.core.runtime.compatibility.auth,
           org.eclipse.core.runtime.compatibility.registry,
           org.eclipse.equinox.preferences,
           org.eclipse.equinox.registry,
           org.eclipse.help,org.eclipse.jface,
           org.eclipse.swt,
           org.eclipse.swt.win32.win32.x86,
           org.eclipse.ui,
           org.eclipse.ui.workbench,
           org.example.rcp.mail
           osgi.bundles.defaultStartLevel=4
           
      Note:

      Eclipse 3.1 set of bundles differs from the 3.2 one. For the list of incompatibilities between RCP 3.1 and RCP 3.2 configuration files, see Eclipse documentation.

      Note:

      If you have exported the application from Eclipse as product, you can find the auto generated file under <exported application folder>\configuration. It is recommended to use this way of file creating. If the incorrect values a provided for these properties, your application will fail to start.

      For more information about this file, see http://help.eclipse.org...runtime-options.html

    • You should end up with a structure similar to the figure below:
  10. Add all required files to the list of compiler resources (Settings | Compiler | Resource patterns), so that IntelliJ IDEA will automatically copy them to the output folder when running and debugging the application.
    Here is an example list:
        ?*.properties;?*.xml;?*.gif;?*.png;?*.jpeg;?*.jpg;
        ?*.html;?*.dtd;?*.tld;
        *.mf;*.bmp;*.ini;*.ico;*.icns;*.product;*.eclipseproduct
        
  11. Create a new application run/debug configuration (Run | Edit configuration), specify the main launcher class (org.eclipse.core.launcher.Main). Set the working directory to the Eclipse RCP installation folder. Note:

    Eclipse periodically requires clearing the cached data. You may either create an external tool for regularly remove of this data or use the osgi.clean system property in the config.ini file.

    If you are migrating the application that is the eclipse product but don't want to use the pure Eclipse RCP with product-specific config.ini file as a target platform, you can provide the
    -product <product.id> program parameter in the RunConfiguration, for example

        -product  org.example.rcp.mail.product
        

    You can use the -application <application.id> option instead;
    For example you can run the same org.example.rcp.mail application like

        -application org.example.rcp.mail.application –data myworkspace
        

    Generally the usual parameters defined for eclipse launcher can be used here.

That's all. Admittedly a bit tricky, but we hope you find the advantages of a familiar development environment and the productivity boost you set with IntelliJ IDEA make a small effort worthwhile. Thanks for using IntelliJ IDEA and keep on developing with pleasure!