如何使用IntelliJ IDEA进行Eclipse插件开发?

52

我需要开发一个Eclipse插件,但我更喜欢使用IntelliJ IDEA作为IDE。有没有可能配置IDEA以进行Eclipse插件开发?


20
为什么被踩?这是一个完全合理的问题。 - maba
2
@maba 有些人只是想看着世界燃烧。 - sMaN
1
https://sites.google.com/site/javafornewbie/frameworks-tools/eclipse/eclipse-rcp-application-development-with-idea#TOC-Configure-the-IDEA-Project-Structure - Justin
有一个问题需要您投票支持:https://youtrack.jetbrains.com/issue/IDEA-124520 - Michel Jung
2个回答

28

使用 Eclipse Tycho 应该是可行的。

你将使用Maven,并且这与IntellIj完美配合。

Tycho专注于基于Maven、以清单为先的方法来构建Eclipse插件、特性、更新站点、RCP应用和OSGi包。Tycho是一组Maven插件和扩展,用于使用Maven构建Eclipse插件和OSGi包。


Tycho仍然没有1.0版本发布。我不确定是否可以在生产中使用它。 - Taras Hupalo
我不认为这会成为一个问题。如果它对你有用并且你开发的插件可以使用,那就直接使用它。 - maba
@TarasHupalo 如果您发现答案有帮助,可以将其标记为已接受。或者给它一个赞。这就是这个网站的工作方式。 - maba
投票需要15点声望。 - Taras Hupalo
看起来像是一个构建工具。Eclipse IDE中对于Eclipse插件的支持还包括调试、生成插件模板、自定义编辑器、轻松识别目标平台等特性... - Andy Thomas
显示剩余2条评论

16

使用Osmorc或许是可能的,但我没有尝试过。然而,我有一种方法可以实现(在 IntelliJ 2017.1 上),但其他版本也应该类似。它不需要使用 Eclipse Tycho,因为我的插件使用了 XCore,这似乎与 Tycho 不兼容。

  • 在Eclipse中创建项目。
  • 创建您的IntelliJ项目。
  • 在IntelliJ中

    1. 文件 > 从现有源创建模块。选择您的eclipse项目。
    2. 从外部模型导入模块

      enter image description here

    3. 为了不破坏Eclipse项目,我选择“保留项目和模块文件在~/IdeaProjects/MyIntelliJProject

    4. 为每个eclipse项目重复此步骤
  • 打开项目结构(Ctrl + Alt + Shift + S

  • 在“全局库”(甚至只是库)中添加一个新的Java库。
  • 选择/opt/eclipse/plugins目录(或者eclipse安装的任何位置)
  • 确保每个模块都将此ECLIPSE库作为最后一个依赖项。
在这个阶段,您应该能够在IntelliJ中编写代码并运行测试,但要实际运行插件,您必须使用Eclipse。不过这有点混乱。
我的解决方案是运行与Eclipse运行插件时相同的命令:
  • 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.

如果我们现在运行该配置,应该可以正常工作。然而,我们仍无法在IntelliJ内部进行调试。以下步骤可以解决此问题:
  • 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").

现在,要调试您的Eclipse插件,请运行Debug Bash Configuration,然后运行Remote Configuration。
最后,我的运行配置看起来像这样:

enter image description here

目前,唯一需要Eclipse的是编辑我的.xcore文件,因为Eclipse可以从中生成Java代码,而XCore没有办法从终端运行。


有一个问题需要您投票支持:https://youtrack.jetbrains.com/issue/IDEA-124520 - Michel Jung

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接