创建 Eclipse 快捷方式来运行构建文件的特定目标
我有不同的项目和几个具有不同目标的构建文件。
通常,如果我想运行目标,我会导航到“Ant”视图,然后选择构建文件,然后选择要运行的目标。
有没有办法为特定目标分配键盘快捷键,以便我可以轻松运行该目标,而不是每次都执行多个步骤。
I have different projects and several build files with different targets in it.
Generally if i want to run a target i use to navigate to 'Ant' view and then select the build file and then selects the target to run.
Instead of doing several steps every time, is there any way to assign a keyboard shortcut for particular target so that i can run that target easily.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
按键的主要首选项页面可以在窗口 > 下找到。首选项>一般> Keys(或更快:按 Ctrl+3,输入 Keys 并按 Enter)。请参阅 如何在 Eclipse 中管理键盘快捷键以及为什么您应该文章来实现您想要的目标。
The main preference page for keys can be found under Window > Preferences > General > Keys (or faster: Press Ctrl+3, type Keys and press Enter) . See How to manage keyboard shortcuts in Eclipse and why you should article to achieve what you want.
好的,我尝试了“EASE-script + 键盘快捷键”技术,效果更好:
我在以下位置创建了一个“my_build_target.js”javascript 文件我的工作区/项目的基础:
请注意标题注释中“魔术关键字”的使用,它指定了脚本所需的快捷键。
然后,您需要指定要加载脚本的位置,方法是:
我个人单击了“ 添加工作空间”按钮并指定了我的工作空间/项目的基础(这是我存放脚本的地方)。
我重新启动了 Eclipse,然后使用我指定的“Alt+Shift+2”快捷键。
太棒了,它有效:)
一个问题是我无法取消使用此方法正在进行的构建。我怀疑这是因为我在调用 .build() 时使用了 NullProgressMonitor 类。如果我了解到在这里添加适当的进度监视器的方法(可以让您取消正在进行的构建),那么我将更新这个答案......
Ok, I've given the "EASE-script + keyboard shortcut" technique a try and that works much better:
I created a "my_build_target.js" javascript file at the base of my workspace/project:
Note the use of the "magic keyword" within the header comment which specifies the desired shortcut-key you want for the script.
You then need to specify the locations for your scripts to be loaded from by going to:
Personally, I clicked the "Add Workspace" button and specified the base of my workspace/project (that's where I housed my script).
I restarted Eclipse and then used my specified "Alt+Shift+2" shortcut key.
Awesome, it works :)
One gotchya is that I can't cancel a build that's in progress with this method. I suspect it's due to me using that NullProgressMonitor class when I call .build(). If I learn of a way to add a proper progress monitor here (that lets you cancel a progressing build), then I will update this answer...
注意:这是我最初的“实用宏 + Beanshell 脚本”技术,我已经放弃了。我更喜欢我的第二个答案中提到的其他技术。
我也一直在寻找一种方法来针对特定的 make 目标执行此操作。唯一可用的内置快捷方式是“重建最后一个目标”,如果您经常在目标之间交换,那么这并不是很有帮助。
虽然我还没有具体的解决方案,但我正在努力实现这一目标。
我正在评估“Practically Macro”插件。它能够为宏分配快捷键。它还能够将宏定义为 beanshell 脚本。
所以剩下的就是弄清楚什么样的 beanshell 脚本能够运行特定的 make 目标。
我尝试通过 EASE 脚本工具探索 Eclipse API。
我将分享我如何以编程方式成功运行 make-target 的步骤/注释(通过他们的 javascript 接口):
所以我认为剩下的就是我(或其他感兴趣的人):
...这是一个相当复杂的方法,所以如果有人有任何更简单的替代方案,我很乐意听取他们的意见。
更新:
FWIW,我设法以这种形式为“实用宏”创建了一个 beanshell 脚本:
是的,它确实起到了一定的作用,但唯一的问题是 eclipse ide 停止运行而没有任何刷新。仅在构建完成后,控制台窗格才会使用最终构建输出进行更新(一次点击),并且 Eclipse 会再次响应。
所以它并不完美,但我认为它是朝着我所追求的方向不断进步......至于导致构建过程中冻结/停滞的原因,我不能肯定地说,但我怀疑实用宏插件锁定Eclipse 直到宏完成。
下次:
也许如果我有另一个时间窗口再次研究这个问题,我会尝试看看是否可以通过键盘快捷键触发 EASE-javascript 脚本。此页面似乎暗示这是可能的:
https://wiki.eclipse.org/EASE/Scripts< /a>
NOTE: This is my initial "Practically Macro + Beanshell script" technique, which I've given up on. I prefer the other technique mentioned in my 2nd answer.
I've been looking for a way to do this for specific make targets too. The only in-built shortcut available is to "Rebuilt Last Target", which isn't all that helpful if you're frequently swapping between targets.
While I don't have a concrete solution yet, I'm working towards one.
I'm assessing the "Practically Macro" plug-in. It has the ability to assign a shortcut key to a macro. It also has the ability to define a macro as a beanshell script.
So all that's left is to figure out what kind of beanshell script would be capable of running a specific make target.
I've tried to explore the Eclipse API via the EASE scripting tool.
I'll share my steps/notes on how I successfully ran a make-target programmatically (via their javascript interface):
So I think all that's left is for me (or someone else that's interested) to:
...quite an involved way to go about it, so if anyone has any simpler alternatives, I'm open to hear them.
UPDATE:
FWIW, I managed to create a beanshell script for "Practically Macro" in this form:
And yes, it does kind-of work, but the only gotchya is that the eclipse ide stalls without any refreshing. Only after the build completes does the console pane get updated with the final build output (in one hit) and Eclipse becomes responsive again.
So it's not perfect, but I suppose it's incremental progress in the direction I'm after... As for what causes this freeze/stall during the build, I can't say for sure, but I suspect that the Practically Macro plugin locks Eclipse up until the macro completes.
Next Time:
Perhaps if I had another window of time to look into this again, I'd try to see if I can trigger an EASE-javascript script via a keyboard shortcut. This page seems to hint that it is possible:
https://wiki.eclipse.org/EASE/Scripts