My team currently use an Ant script to execute various Java programs.
Note that I am not asking about managing the build/deployment cycle for which we are already using Maven (quite happily).
For example, we use something like the following:
<path id="lib">
<fileset dir="path/to/lib" />
</path>
<path id="run" >
<path refid="lib" />
</path>
<target name="aJavaProgram" >
<java classname="path.to.AJavaProgam"
classpathref="run" fork="yes" failonerror="false" append="true" />
</target>
<target name="anotherJavaProgram" depends="aJavaProgram" >
<java classname="path.to.AnotherJavaProgam"
classpathref="run" fork="yes" failonerror="false" append="true" />
</target>
We originally chose Ant for the following reasons (or rather I didn't choose Ant, it was that way when I joined, but I think these are good reasons for the choice):
- it was an easy way of managing dependencies (although we now pick up these from Maven)
- it allows us to easily build/maintain dependencies between particular jobs
- we can deploy the Ant script, and the Java libraries, and easily run particular jobs - i.e.
- we don't have to worry about classpaths (configured in the Ant script)
- we don't have to worry about building jars with main classes specified in the manifest
- we can use Ant to create / store / manage arguments passed to main() methods
- we can plug these ant scripts into our IDEs and run the jobs from there.
Generally speaking, we have been very happy with this.
However, an increasing issue is the ant-java-shutdown hook issue - this means that if one of these Java programs fails but doesn't finish, terminating the Ant process from which it was started doesn't terminate the Java process - which then has to be done manually, and is a real bind.
Also, I'm conscious of two other (possible) factors:
- this is using Ant in a slightly unusual way, which is perhaps not how Ant was intended to be used (or at least, so it seems to me...)?
- I'm not really sure, but it seems that fewer and fewer developers/teams are using Ant these days, with preference for other technologies.
So, to clarify:
- I want a flexible approach to execute various Java programs
- the approach that we have been using was to do this via Ant scripts, but this had the following problems:
- terminating the Ant task does not kill the Java program
- this "feels" like Ant is not the right tool for the job
- how might we meet the needs specified above?
- if not Ant, the solution should not face the termination / shutdown hook issue