为特定Eclipse构建配置分配键盘快捷键

spl*_*tor 22 eclipse keyboard-shortcuts

在Eclipse的Java项目中,我们有几个构建配置,因为我们有一个引擎,在运行时,根据它获得的参数为特定项目构建安装jar,因此每个构建配置使用不同的参数运行相同的构建来构建安装对于特定项目.

目前,我得去运行配置下拉工具栏中的按钮启动发动机,我需要才能运行(或调试)与所需参数的发动机从列表中选择构建配置.

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

Jer*_*lin 25

我能够基于splintor的线程组合特定的步骤并使其工作(我还在顶部添加了一个循环,找到任何具有相同名称的现有启动并终止它,有效地使这成为"重启"宏):

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

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

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

  • 单击"编辑器宏定义"

  • 点击"新..."

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

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

    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{}
    
    Run Code Online (Sandbox Code Playgroud)
  • 注意第11行检查配置名称,替换为您想要的任何内容

  • 还要注意第15行的DebugUITools.launch命令,你可以传递"run"或"debug"

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

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

  • 单击确定

  • 展开"常规"部分,然后单击"密钥"

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

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


spl*_*tor 9

我能够使用实际宏来实现它- 请参阅此主题.

  • 我检查了线程以使其工作并提供了所列出的确切步骤的答案. (3认同)

Von*_*onC 5

您可以在其中定义一些插件launchShortcuts.

这个帖子很好.

但要实际绑定它,您需要定义运行该配置的命令,并将该命令绑定到一个键(如此plugin.xml配置文件中)

启动配置的快捷方式定义:

  <shortcut id="org.maven.ide.eclipse.pomFileAction"
            category="org.maven.ide.eclipse"
            class="org.maven.ide.eclipse.actions.ExecutePomAction"
            icon="icons/m2.gif"
            label="%m2.popup.pomFile.label"
            modes="run,debug">
     <contextualLaunch>
       <contextLabel label="%m2.popup.pomFile.label" mode="run"/>
       <contextLabel label="%m2.popup.pomFile.label" mode="debug"/>
       <enablement>
         <with variable="selection">
           <count value="1"/>
           <iterate>
             <and>
               <test property="org.maven.ide.eclipse.launchable"/>
               <adapt type="org.eclipse.core.runtime.IAdaptable"/>
             </and>
           </iterate>
         </with>
       </enablement>
   </contextualLaunch>
 </shortcut>
Run Code Online (Sandbox Code Playgroud)

然后命令:

 <extension point="org.eclipse.ui.commands">
    <command id="org.maven.ide.eclipse.pomFileAction.run"
             categoryId="org.eclipse.debug.ui.category.run"
             name="%m2.shortcut.description.run"
             description="%m2.shortcut.description.run"/>
     ...
 </extension>
Run Code Online (Sandbox Code Playgroud)

然后是键盘快捷键的键绑定:

<extension point="org.eclipse.ui.bindings">
    <key sequence="M3+M2+X M"
         contextId="org.eclipse.ui.globalScope"
         commandId="org.maven.ide.eclipse.pomFileAction.run"
         schemeId="org.eclipse.ui.defaultAcceleratorConfiguration"/>
 </extension>
Run Code Online (Sandbox Code Playgroud)


Lii*_*Lii 5

另一种方法是使用加速键来导航"运行"菜单并选择正确的运行配置.

在我的电脑上它是:

Alt+ R,H,Number

Alt+ R让你进入Run菜单,然后H是Debug History,然后是其中一个编号的替代品.

要使运行配置始终在"调试"或"运行历史记录"菜单中可见并保留其位置,可以执行以下操作:

选择运行菜单 - > 运行配置 - > [某些配置] - > 通用,然后选中显示在收藏夹菜单框中.

(这个答案是我以前的一个答案的副本.)