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.
- The reader should be acquainted with the Eclipse platform architecture.
- You can download the current version of Eclipse Rich Client Platform from Eclipse site.
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:
- Create a test application in Eclipse
- Prepare for migration
- Migrate the application to IntelliJ IDEA
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:
- Create new Plug-in project. The project name should be org.example.rcp.mail. Choose the RCP Mail Template as template.
- 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.
- Make sure that all the required plugins are added to the project configuration.
- Export Eclipse product into some directory (called product directory below).
Preparing for migration
- Since the structure of Eclipse plugin will be modified to build from IntelliJ IDEA, copy the whole content of your RCP plugin. The new directory (for example, <Eclipse workspace>/org.example.rcp.mail2) is called working directory below.
- Remove or back up the plugin's output produced by Eclipse: <product directory>/plugins/org.example.rcp.mail directory or <product directory>/plugins/org.example.rcp.mail_*.jar archive. This will be replaced with the output produced by IntelliJ IDEA.
Migrating to IntelliJ IDEA
Now, let's turn to IntelliJ IDEA:
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.
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:
- 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.
- 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.
Add the newly created Eclipse RCP library to the dependencies of the Mail module.
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.
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.
The next thing is to set this application up for running and debugging it from within IntelliJ IDEA.
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:
- Mark the resources directory as the Mail module source (Project Structure | Modules ? Sources tab):
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.
Make the Mail module dependent on this new Descriptor module. For this purpose, add the Descriptor module to the classpath of the Mail module.
- 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:
- 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:
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.
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
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!