为特定的 Eclipse 构建配置分配键盘快捷键 [英] Assigning a keyboard shortcut for a specific Eclipse build configuration

查看:22
本文介绍了为特定的 Eclipse 构建配置分配键盘快捷键的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我们在Eclipse中的Java项目中,我们有几个构建配置,因为我们有一个引擎,当运行时,根据它得到的参数为特定项目构建安装jar,所以每个构建配置运行不同参数的相同构建为特定项目构建安装.

In our Java project in Eclipse, we have several build configurations, as we have an engine that when run, builds installation jar for a specific projects according to the parameters it gets, so each build configuration run the same build with different parameters to build installation for a specific project.

目前,我必须转到工具栏中的运行配置"下拉按钮才能启动引擎,我需要从列表中选择构建配置,以便使用所需参数运行(或调试)引擎.

Currently, I have to go to the Run Configuration drop-down button in the toolbar to start the engine, and I need to select the build configuration from the list in order to run (or debug) the engine with the required parameters.

如果按钮运行而不是从下拉菜单中选择,我已将 Eclipse 配置为运行最后一次运行执行,但我真的希望在工具栏中为每个构建配置(或我最喜欢的配置)有单独的按钮),甚至更好的是,有一个运行(或调试)特定构建配置的键盘快捷键.这可能吗?

I have configured Eclipse to run the last run execution if the button is run instead of selecting from the drop-down menu, but I would really like to have separate buttons in the toolbar for each build configuration (or for my favorite configurations), and even better, have a keyboard shortcut to run (or debug) a specific build configuration. Is that possible?

推荐答案

我能够根据 splintor 的线程将特定步骤放在一起并使其正常工作(我还在顶部添加了一个循环,用于查找任何具有相同名称的现有启动并终止它,从而有效地使其成为重新启动"宏):

I was able to put together specific steps based on splintor's thread and get this working (I also added a loop at the top that finds any existing launch with the same name and terminates it, effectively making this a "restart" macro):

要将键盘快捷键分配给特定的 Eclipse 启动配置,请执行以下步骤:

To assign keyboard shortcuts to specific Eclipse launch configurations, perform the following steps:

  • Install https://sourceforge.net/projects/practicalmacro/, which you can inside Eclipse via Help->Software Updates: http://puremvcnotificationviewer.googlecode.com/svn/trunk/PracticallyMacroGoogleUpdateSite

重新启动 Eclipse 并打开 Eclipse 首选项.你会有一个新的称为实际宏选项"部分,展开该部分.

Restart Eclipse and open Eclipse Preferences. You will have a new section called "Practically Macro Options", expand that section.

点击编辑器宏定义"

点击新建..."

在可用命令列表中,向下滚动到编辑器宏脚本(Beanshell)",选择它,然后单击添加->"

In the list of available commands, scroll down to "Editor Macro script (Beanshell)", select it and then click "Add->"

当脚本编辑器弹出时,在现有代码中加入如下代码:

When the script editor pops up, add the following code to the existing code:

import org.eclipse.debug.core.DebugPlugin;
import org.eclipse.debug.core.ILaunchConfiguration;
import org.eclipse.debug.core.ILaunch;
import org.eclipse.debug.ui.DebugUITools;
    try
    {
      // Terminate process if it already exists from a previous launch 
      org.eclipse.debug.core.ILaunch[] allLaunches=DebugPlugin.getDefault().getLaunchManager().getLaunches();
      for (ILaunch l : allLaunches)
      {              
        if (l.getLaunchConfiguration().getName().equals("YOUR CONFIG NAME HERE"))
        {
          console.write("terminating launch: " );
          console.writeln(l.getLaunchConfiguration().getName());
          l.terminate();
          break; 
        }
      }

        org.eclipse.debug.core.ILaunchConfiguration[] allConfigurations=DebugPlugin.getDefault().getLaunchManager().getLaunchConfigurations();
        for (ILaunchConfiguration config : allConfigurations) {
            if (config.getName().equals("YOUR CONFIG NAME HERE"))
            {
                DebugUITools.launch(config, "debug");
                break;
            }
        }
    } catch (CoreException e) {
        e.printStackTrace();
    }
    finally{}

  • 注意检查配置名称的第 11 行,替换为您想要的任何内容

  • Note line 11 that checks the configuration name, replace with whatever you want

    还要注意第 15 行的 DebugUITools.launch 命令,您可以传递运行"或调试"

    Also note DebugUITools.launch command on line 15, you can pass either "run" or "debug"

    在此对话框底部的宏信息"部分,指定宏名称

    In the "Macro info" section at the bottom of this dialog, specify a macro name

    重要提示!:如果您希望能够在标准的 Eclipse 键绑定对话框中看到这个宏,您需要分配一个 id.我从 1 开始...

    IMPORTANT!: If you want to be able to see this macro in the standard Eclipse key binding dialog, you need to assign an id. I started with 1...

    点击确定

    展开General"部分并点击Keys"

    Expand the "General" section and click on "Keys"

    您现在可以搜索新宏名称的可能键绑定,并将其分配给您想要的任何键.

    You can now search the possible key bindings for your new macro's name and assign it to any key you want.

    注意:在分配一个键后,我经常不得不关闭并重新启动 Eclipse,然后才能尊重键绑定.

    NOTE: After assigning a key I often had to close and restart Eclipse before the key binding was respected.

    这篇关于为特定的 Eclipse 构建配置分配键盘快捷键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

  • 查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆