Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Eclipse: On Save execute a program

Tags:

eclipse

I have recently come across the LESS Leaner CSS a 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.

In Eclipse, there are "Save-Actions" but it handles only formatting changes.

Is there a way on saving the file in Eclipse, to call or trigger the compilation?

Its easy to do this in Vi or Emacs.

like image 672
lud0h Avatar asked Jun 18 '09 11:06

lud0h


People also ask

How do I save and run in Eclipse?

Preferences > Run/Debug > Launching. There's a setting called "Save required dirty editors before launching". Set it to "Always". Show activity on this post.

How do I save an entire project in Eclipse?

Right click on the project, choose Source -> Clean up... to run the save actions, and under Source you will also have Organize imports and Format . If "Source" is not available on the Project, try right clicking on the source folder.

Why is Eclipse running previous program?

My suspicion is you have settings which are causing it to launch the last launched item, rather than something new that does not have a launch configuration. If you hover over the Run icon, it will show the name of the launch configuration that Eclipse will launch.


2 Answers

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.

Right click on the project -> Properties -> Builders -> New

like image 79
Michael Borgwardt Avatar answered Sep 24 '22 19:09

Michael Borgwardt


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.

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

like image 33
zvikico Avatar answered Sep 22 '22 19:09

zvikico