2

Has anybody discovered any means to fire an ant build process automatically based on file system changes?

I basically want my ant build system to begin building similar to an IDE (compile java classes) but from some sort of command line service.

If not, there's always coding one up with Java and integrating the Ant API into it.

I am familiar with continuous integration systems like Jenkins and the like, however I need the build to be fired not check-in. Also I would like it to be independent of the IDE, as that could work on post-save.

I'm looking for an independent build service without source control requirements.

ricosrealm
  • 1,616
  • 1
  • 16
  • 26

3 Answers3

2

Since you are using ant I assume a java based directory polling program will help here. You can write a program using IO notification api

Notes from the page

When to Use and Not Use This API

The Watch Service API is designed for applications that need to be notified about file change events. It is well suited for any application, like an editor or IDE, that potentially has many open files and needs to ensure that the files are synchronized with the file system. It is also well suited for an application server that watches a directory, perhaps waiting for .jsp or .jar files to drop, in order to deploy them.

This API is not designed for indexing a hard drive. Most file system implementations have native support for file change notification. The Watch Service API takes advantage of this support where available. However, when a file system does not support this mechanism, the Watch Service will poll the file system, waiting for events.

Edit

After I wrote that this question and its answer seems to be more useful here: Is there a sophisticated file system monitor for Java which is freeware or open source?

Community
  • 1
  • 1
Jayan
  • 18,003
  • 15
  • 89
  • 143
  • +1 for the link - JNotify looks like the right approach. If I can link this up with Ant as an embedded script, it would work nicely. I'll give it a shot and then update the answer. – ricosrealm Feb 11 '12 at 10:16
  • Update: JNotify is a nice implementation. I was able to integrate the Ant API and JNotify very easily to monitor file changes and fire the build or targets specifically as needed. IO Notifications via Java 7 WatchService is another route, but I haven't tried that. – ricosrealm Feb 18 '12 at 02:36
1

The widely practiced way is a way of "continuous build" / "continuous integration". A sample work-flow:

  1. You check in your code into a source control repository
  2. Continues Integration server picks up changes from the repository and starts a build process
  3. The build process results in either success or failure giving you a fast feedback

Lot's of continuous integration servers (Bamboo, Jenkins, Go) support Ant natively.

You can also set up post-save hooks in your IDE. Most modern ones support it: IntelliJ, NetBeans, Eclipse.

Look up "continuous integration" in google.

Yuriy Zubarev
  • 2,821
  • 18
  • 24
  • Yes this is a good answer. Let me update the question as am familiar with these, but I need something that works independently from an IDE and not on check-in. – ricosrealm Feb 10 '12 at 22:50
  • Or if you can clarify... can Jenkins, Bamboo, etc do this without source control check-ins? – ricosrealm Feb 10 '12 at 22:56
  • Not as far as I know. Source control systems are in DNA of continues integration servers. – Yuriy Zubarev Feb 10 '12 at 22:58
0

A friend pointed me to this:

https://serverfault.com/questions/179706/how-can-i-trigger-a-script-to-run-after-the-rsyncdaemon-received-file-changes-to

A little script to monitor for changes and execute and independent task.

If anyone has a better method that works with ANT scripts directly, let me know.

Community
  • 1
  • 1
ricosrealm
  • 1,616
  • 1
  • 16
  • 26