Sebastian Barth
Sebastian Barth

Reputation: 4521

Trigger Eclipse clean via command line or automatically at a specified time

Is it anyhow possible to force a running Eclipse to clean and rebuild from command line in linux or time triggered?

I have a workspace with hundreds of Maven projects that have to be cleaned an rebuild after a file change automatically. The file change is happening every night triggered by a cronjob which runs svn update followed by a mvn clean and a mvn install at the end. Eclipse itself sees those source changes and rebuilds automatically (native hooks) to keep being up to date. But because of unknown reasons it does not rebuild completely. A lot of errors and warnings remain. Those errors disappear only if I clean the whole Eclipse workspace which then results in an automatic rebuild in Eclipse. This rebuild takes a long time (> 1 hour). I don't want to spend this time every day. So I'm looking for a automatic way to force a complete clean and rebuild of my workspace of a running eclipse over night.

I can't restart eclipse over night.

One idea is to clean Eclipse from outside (but how?) to let it notice the change by itself. Eclipse might then rebuild automatically.

Upvotes: 3

Views: 975

Answers (1)

hiergiltdiestfu
hiergiltdiestfu

Reputation: 2357

As far as I'm aware, there's no predefined way to trigger this from the outside. So I'm going to propose a strategy which can achieve what you need. This touches on a lot of advanced topics so I'm only going to provide some pointers to get you started, because bringing all the details will be too much for this format. It would probably make an excellent blog article tho. So here we go:

  1. Write a plugin for your Eclipse.
  2. This plugin hast to expose an MXBean with a Clean-and-Rebuild operation. Use the JDK tool jconsole to check the operation's accessibility.
  3. That operation in turn executes the clean and the full rebuild commands. You can use the Eclipse Plug-in Spy to find the appropriate command contributions, and/or scour the Eclipse source code.
  4. Then, you need to build a custom JMX client which invokes that MXBean operation from the outside. This is basically a stripped down version of jconsole's JMX capabilities and can be a simple Java command line app your cron job calls. It needs to connect to your local Eclipse instance and invoke the operation you defined earlier. In order to find the correct instance to connect to, your Eclipse plugin could write the port of the instance's MXBean server to a file your JMX client looks for at startup.

EDIT: In addition to the clean and rebuild commands, you'll want to invoke a full refresh of the workspace beforehand.

Upvotes: 3

Related Questions