Eclipse:在保存时执行程序
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1012230/
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
Eclipse: On Save execute a program
提问by lud0h
I have recently come across the LESS Leaner CSSa template engine for CSS based on ruby. The idea sounded neat, but in practice we need to compile the program to get CSS. This is cumbersome as we make too many changes while working on CSS and for every edit we don't want to compile.
我最近遇到了LESS Leaner CSS一个基于 ruby 的CSS模板引擎。这个想法听起来不错,但实际上我们需要编译程序来获取 CSS。这很麻烦,因为我们在处理 CSS 时进行了太多更改,并且对于我们不想编译的每个编辑。
In Eclipse, there are "Save-Actions" but it handles only formatting changes.
在 Eclipse 中,有“保存操作”,但它只处理格式更改。
Is there a way on saving the file in Eclipse, to call or trigger the compilation?
有没有办法在 Eclipse 中保存文件,调用或触发编译?
Its easy to do this in Vi or Emacs.
在 Vi 或 Emacs 中很容易做到这一点。
回答by Michael Borgwardt
I think all you need is to define a custom Builder for your project. That way, you can run a program or an ant script whenever certain files change.
我认为您所需要的只是为您的项目定义一个自定义构建器。这样,您就可以在某些文件发生更改时运行程序或 ant 脚本。
Right click on the project -> Properties -> Builders -> New
右键单击项目 -> 属性 -> Builders -> 新建
回答by zvikico
While the Builders are a good solution, keep in mind they only work when a build is issued - either using auto-build or using a manual build which is invoked, well, manually. If you are looking for something that will operate after a save, regardless of the auto-build state you will need to write a plugin which listens to resource changes in Eclipse.
虽然构建器是一个很好的解决方案,但请记住,它们仅在发布构建时工作 - 使用自动构建或使用手动调用的手动构建,好吧,手动。如果您正在寻找可以在保存后运行的东西,无论自动构建状态如何,您都需要编写一个插件来侦听 Eclipse 中的资源更改。
You do that by creating a workspace change listener and installing it like that:
您可以通过创建工作区更改侦听器并像这样安装它来做到这一点:
ResourcesPlugin.getWorkspace().addResourceChangeListener(
..., IResourceChangeEvent.POST_CHANGE);
I'm sure you can take it from here :-)
我相信你可以从这里拿走它:-)