IntelliJ IDEA How-To

Using IntelliJ IDEA for Eclipse RCP development

Introduction

This article describes how to migrate applications developed in Eclipse Rich Client Platform (RCP) to IntelliJ IDEA. Because of the Eclipse architecture, such applications are implemented as plugins to Eclipse platform. However, this does not mean you absolutely must use Eclipse Java Development Toolkit (itself a plugin to 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 intricate (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

Migrating RCP application to IntelliJ IDEA

To demonstrate the migration process and possible mappings of files and folders to the IntelliJ IDEA project structure, we have considered the Eclipse plugin project based on "RCP Mail Template" created using Eclipse PDE. This template generates a standalone RCP application, complete with views, menu and toolbar actions, key bindings and a product definition.

The whole process falls into the following major steps:

Let us consider these steps in more detail.

Creating test application in Eclipse

To get a similar test application, perform the following steps in Eclipse:

  1. Create new Plug-in project. The project name should be org.example.rcp.mail. Choose the RCP Mail Template as template.
  2. Create Product Configuration for your plugin to make this application deployable as Eclipse product. We consider a simple application structure that contains only one project without any external dependencies.
  3. Make sure that all the required plugins are added to the project configuration.
  4. Export Eclipse product into some directory (called product directory below).

Preparing for migration

Migrating to IntelliJ IDEA

Now, let's turn to IntelliJ IDEA:

  1. In IntelliJ IDEA, create a new project with a single Java module. The project file can be located in your Eclipse workspace. The module name should be Mail.
    Create Project
  2. Configure the module content root, output directory, and libraries. To do that, use the Project Structure dialog:
    • Set the module content root point to your working directory, so that all the files that are generated by Eclipse (such as plugin.xml or manifest.mf) will be automatically added to the module. See the screenshot below:
      Screenshot

      Pop up larger screenshot

    • Set the module's output directory to point to <product directory>/plugins/org.example.rcp.mail. IntelliJ IDEA will automatically create this directory to use it as a compilation output, so Eclipse RCP platform will find your plugin during startup.
      Screenshot

      Pop up larger screenshot

      Note: Make sure that in the Settings | Compiler the Clear output directory on rebuild checkbox is not selected:
      Screenshot

      Pop up larger screenshot

      Otherwise you can accidentally remove the RCP installation.
    • Create a new project library (Project Structure / Libraries), name it Eclipse RCP and add to this library all jars and directories with compiled java classes from <product directory>/plugins.
      Screenshot

      Pop up larger screenshot

    • Add the newly created Eclipse RCP library to the dependencies of the Mail module.
      Add Eclipse Rcp Library As Dependency
      Note: If you need more jars or Eclipse RCP plugins later, you can add them to this library, or create new libraries for them.

      Now, your project is configured and ready for further work.

  3. At this point make your project. If all classes are added correctly and the sources are correct, then Make should be successful. Now you can edit your RCP application in IntelliJ IDEA, use code completion and navigation features, view folded code, documentation, etc. ? just enjoy.
    IDEA Features
    The next thing is to set this application up for running and debugging it from within IntelliJ IDEA.
  4. For running and debugging purposes, we use JARs from the Eclipse RCP library, 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 product directory (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:
      Move Resources
    • Mark the resources directory as the Mail module source (Project Structure | Modules ? Sources tab):
      Screenshot

      Pop up larger screenshot

  5. If you are developing the application that is an Eclipse product and try to run it with pure Eclipse RCP, you need two files: config.ini and .eclipseproduct in the product directory. If you have performed Product export from Eclipse, then these files are already there.

    If you plan to modify the product configuration (product id property, required bundles etc.) and want the properly changed config.ini and .eclipseproduct files to be deployed to the target platform by IntelliJ IDEA, you may follow the instructions below. Otherwise, skip to step 6.

    • 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 product directory.
      Output Directory For Descriptor Module
    • Make the Mail module dependent on this new Descriptor module. For this purpose, add the Descriptor module to the classpath of the Mail module.
      Added Dependency Module From Desvriptor
    • Create the .eclipseproduct file in the source directory of the Descriptor module. Check the product file produced by Eclipse for the required file format.
    • Create the configuration folder within the source folder of the Descriptor module, and create the config.ini file in it. Check the configuration file produced by Eclipse for the required file format.
    • You should end up with a structure similar to the figure below:
      Final Structure
  6. 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
  7. Create a new application run/debug configuration (Run | Edit configuration), set Use classpath and JDK of a module to Mail, and specify the main launcher class (org.eclipse.core.launcher.Main). Set the working directory to the product directory.
    Run Configuration For Mail Module

    None: Eclipse periodically requires clearing the cached data. You may either create an external tool for regularly removing these data, or use the osgi.clean system property in the config.ini file.

    If you are migrating the application that is an Eclipse product, but don't want to use the pure Eclipse RCP with product-specific config.ini file as the 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 get with IntelliJ IDEA make a small effort worthwhile. Thanks for using IntelliJ IDEA and keep on developing with pleasure!