How to use IntelliJ IDEA for Eclipse plugin development?

Intellij IdeaEclipse PluginEclipse Rcp

Intellij Idea Problem Overview


I have to develop a plugin for Eclipse but I prefer IntelliJ IDEA as IDE. Is it possible to configure IDEA for Eclipse plugin development?

Intellij Idea Solutions


Solution 1 - Intellij Idea

It should be possible by using Eclipse Tycho.

You'll be using maven and that works perfectly with IntellIj.

> Tycho is focused on a Maven-centric, manifest-first approach to building Eclipse plug-ins, features, update sites, RCP applications and OSGi bundles. Tycho is a set of Maven plugins and extensions for building Eclipse plugins and OSGi bundles with Maven.

Solution 2 - Intellij Idea

It might be possible using Osmorc, but I haven't tried that. However, I have a method that works (using IntelliJ 2017.1, but it should be similar for other versions). It does not require Eclipse Tycho, which I couldn't use because my plugin used XCore which doesn't seem compatible with Tycho.

  • Create the projects in Eclipse.

  • Create your IntelliJ project.

  • Inside IntelliJ

    1. File > New > Module from existing sources. Select your eclipse project.

    2. Import module from external model

      enter image description here

    3. In order to not mess up the Eclipse projects, I selected "Keep project and module files in ~/IdeaProjects/MyIntelliJProject

    4. Repeat for each eclipse project

  • Open up the Project Structure (Ctrl + Alt + Shift + S)

  • In "Global Libraries" (or even just Libraries), add a new Java library.

  • Select the /opt/eclipse/plugins directory (or wherever eclipse was installed)

  • Ensure each module has this ECLIPSE library as the last dependency.

At this point, you should be able to code and run tests in IntelliJ, but to actually run the plugin, you have to use Eclipse. That's a bit messy, though.

My solution was to run the same command that Eclipse does when you run your plugin:

  • Get the BashSupport IntelliJ plugin (may have to be something else on Windows; maybe you can run a batch file)

  • In Eclipse, run your plugin (Run Eclipse Application).

  • Open up the Debug perspective. You should see something like this:

    Debug stack

  • Right click > properties on the /usr/lib/jvm/... (may be different Java JVM)

  • Copy the Command Line:

    Process Properties

  • Elsewhere, in your favorite editor, make a new bash file (I put this file in my IntelliJ project folder), and paste this command in there.

  • Note that when Eclipse runs the command, it runs from a working directory of /opt/eclipse/ (or wherever eclipse is installed), so we need to add a cd /opt/eclipse/ beforehand. Let's do it in a new shell as well:

      (cd /opt/eclipse && /usr/lib/jvm/java-8-oracle/bin/java ...)
    

    If this bash script is run, it should be the same as if we ran from Eclipse.

  • In IntelliJ, create a new Bash run configuration (Alt + Shift + F10 > Edit Run Configurations). Make the "Script:" field contain the path to the bash file we just created.

    Also, add "Build Project" to the "Before launch" options.

    Additionally, tick the "Single instance only" box.

If we now run that configuration, it should work. However, we still cannot debug from within IntelliJ. This fixes that:

  • Create a new IntelliJ run configuration of type "Remote", marking it as "Single instance only"

  • Copy the "Command line arguments for running remote JVM". For me that is

      -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005
    

    I liked the workflow for suspend=y better; basically it means that the eclipse application won't start up until we attach the debugger.

  • Copy your bash file and add these arguments:

      (cd /opt/eclipse && /usr/lib/jvm/java-8-oracle/bin/java -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005 ...)
    
  • Add another Bash run configuration for IntelliJ that runs this new script (and also runs "Build Project" beforehand, and is "Single instance only").

Now, to debug your Eclipse plugin, run the Debug Bash Configuration, then run your Remote Configuration.

At the end, this is what my run configurations look like:

enter image description here

At this point, the only thing Eclipse is needed for is editing my .xcore files since Eclipse generates Java code from that, and XCore doesn't have a way to be run from the terminal.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionTaras HupaloView Question on Stackoverflow
Solution 1 - Intellij IdeamabaView Answer on Stackoverflow
Solution 2 - Intellij IdeaJustinView Answer on Stackoverflow