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

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

问题描述

在我们在Eclipse中的Java项目中,我们有几个构建配置,因为我们有一个引擎,当运行时,根据其获取的参数为特定项目构建安装jar,因此每个构建配置都使用不同的参数运行相同的构建为特定项目构建安装。



目前,我必须到工具栏中的运行配置下拉菜单启动引擎,我需要选择从列表中构建配置,以便运行(或调试)具有所需参数的引擎。



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

解决方案

我能够根据splintor的线程和得到这个工作(我也在顶部添加了一个循环,发现任何现有的启动具有相同的名称,并终止它,有效地使其成为重启宏):



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




  • 安装 https://sourceforge.net/projects/practicalmacro/ ,您可以通过帮助 - >软件更新
    $ b http://puremvcnotificationviewer.googlecode.com/svn/trunk/PracticallyMacroGoogleUpdateSite


  • 重新启动Eclipse并打开Eclipse Preferences。您将有一个新的
    部分,称为实际宏选项,展开该部分。


  • 点击编辑器宏定义


  • 点击新...


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


  • 当脚本编辑器弹出时,添加以下代码到现有代码:

      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
    {
    //如果从以前的启动已经存在,则终止进程
    org.eclipse.debug.core.ILaunch [] allLaunches = DebugPlugin.getDefault()。getLaunchManager ().getLaunches();
    (ILaunch l:allLaunches)
    {
    if(l.getLaunchConfiguration()。getName()。equals(你的配置名称在这里))
    {
    console.write(terminate launch:);
    console.writeln(l.getLaunchConfiguration()。getName());
    l.terminate();
    break;
    }
    }

    org.eclipse.debug.core.ILaunchConfiguration [] allConfigurations = DebugPlugin.getDefault()。getLaunchManager()。getLaunchConfigurations();
    (ILaunchConfiguration config:allConfigurations){
    if(config.getName()。equals(你的配置名称在这里)
    {
    DebugUITools.launch(config,调试);
    break;
    }
    }
    } catch(CoreException e){
    e.printStackTrace();
    }
    finally {}


  • 注意第11行检查配置名称,替换你想要的任何东西


  • 另请注意第15行DebugUITools.launch命令,你可以传递运行或调试 >


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


  • 重要!:如果您希望能够在标准Eclipse键绑定对话框中看到此宏,则需要分配一个id。我开始使用1 ...


  • 单击确定


  • 展开常规部分,然后点击键


  • 现在,您可以搜索可能的键绑定以获取新宏的名称,并将其分配给所需的任何键。


  • 注意:分配密钥后,我经常不得不关闭并重新启动Eclipse,然后才能遵守密钥绑定。



    • 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.

      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?

      解决方案

      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):

      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

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

      • Click on "Editor Macro Definitions"

      • Click on "new..."

      • 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{}
        

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

      • 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

      • 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...

      • Click OK

      • 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.

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

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

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