为特定的 Eclipse 构建配置分配键盘快捷键
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1437323/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Assigning a keyboard shortcut for a specific Eclipse build configuration
提问by splintor
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.
在我们的Eclipse Java项目中,我们有几个构建配置,因为我们有一个引擎,当运行时,根据它得到的参数为特定项目构建安装jar,所以每个构建配置运行相同的构建,使用不同的参数来构建安装用于特定项目。
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?
如果按钮运行而不是从下拉菜单中选择,我已将 Eclipse 配置为运行最后一次运行执行,但我真的希望在工具栏中为每个构建配置(或我最喜欢的配置)有单独的按钮,并且更好的是,有一个键盘快捷键来运行(或调试)特定的构建配置。那可能吗?
回答by Jeremy Mullin
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):
我能够根据 splintor 的线程将特定步骤放在一起并使其正常工作(我还在顶部添加了一个循环,用于查找具有相同名称的任何现有启动并终止它,从而有效地使其成为“重新启动”宏):
To assign keyboard shortcuts to specific Eclipse launch configurations, perform the following steps:
要将键盘快捷键分配给特定的 Eclipse 启动配置,请执行以下步骤:
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.
安装https://sourceforge.net/projects/practicalmacro/,您可以通过 Help->Software Updates 在 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{}
注意检查配置名称的第 11 行,替换为您想要的任何内容
另请注意第 15 行的 DebugUITools.launch 命令,您可以传递“运行”或“调试”
在此对话框底部的“宏信息”部分,指定宏名称
重要提示!:如果您希望能够在标准 Eclipse 键绑定对话框中看到这个宏,您需要分配一个 id。我从1开始...
单击确定
展开“常规”部分,然后单击“键”
您现在可以搜索新宏名称的可能键绑定并将其分配给您想要的任何键。
注意:在分配一个键后,我经常不得不在键绑定被遵守之前关闭并重新启动 Eclipse。
回答by splintor
I was able to do it using Practically Macro- see this thread.
回答by VonC
You could define a plugin with some launchShortcuts
in it.
您可以定义一个包含一些插件的插件launchShortcuts
。
This threadis a good illustration.
这个线程是一个很好的例证。
But to actually bind it, you would need to define a command running that configuration, and bind that command to a key (like in this plugin.xml
configuration file)
但要实际绑定它,您需要定义一个运行该配置的命令,并将该命令绑定到一个键(就像在这个plugin.xml
配置文件中一样)
the shortcut definition of a launch configuration:
启动配置的快捷方式定义:
<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>
Then the command:
然后命令:
<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>
Then the key binding for a keyboard shortcut:
然后是键盘快捷键的键绑定:
<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>
回答by Lii
One alternative is to use the accelerator keys to navigate the Run menu and select the right run configuration.
一种替代方法是使用加速键导航“运行”菜单并选择正确的运行配置。
On my computer it is:
在我的电脑上是:
Alt+ R, H, Number
Alt+ R, H,Number
Alt+Rgets you to get to Run menu, then Hfor Debug History, then one of the numbered alternatives.
Alt+R让您进入“运行”菜单,然后H进入“调试历史”,然后进入编号选项之一。
To make a run configuration always be visible in the Debug or Run history menus and retain its position one can do the following:
要使运行配置始终在调试或运行历史记录菜单中可见并保持其位置,可以执行以下操作:
Select the Runmenu -> Run Configurations-> [some config] -> Common, then check Display in favourites menubox.
选择Runmenu -> Run Configurations-> [some config] -> Common,然后在收藏夹菜单框中选中Display。
(This answer is a copy of one of my previous answers.)
(这个答案是我之前的一个答案的副本。)