Newsletter sign-up
View all newsletters

Enterprise Java Newsletter
Stay up to date on the latest tutorials and Java community news posted on JavaWorld

Sponsored Links

Optimize with a SATA RAID Storage Solution
Range of capacities as low as $1250 per TB. Ideal if you currently rely on servers/disks/JBODs

Automate your build process using Java and Ant

Introducing the powerful XML-based scripting tool, Ant

  • Print
  • Feedback

Page 5 of 5

      <remoteCopy machine="machinename.groupserve.com" port="9090"
directory="e:\deve\ant\article\deploy" filetype="text"
filename="build.xml"/>


The remoteCopy task will execute the RemoteCopyTask object and in doing so, connect to the machine/port specified and copy the file over. That task includes properties identifying the server/port of the RemoteAntServer. Also, please note that the three file-related properties correspond with the accessor methods contained in the RemoteCopyTask object. Those values are converted into calls to those methods.

The remoteAnt task has been defined by using a similar taskdef object:

      <taskdef name="remoteAnt" classname="local.RemoteAntTask"/>


The following task will execute the ant command on the remote machine:

      <remoteAnt machine="machinename.groupserve.com" port="9090" />


Again, note that several command line tags are given when the server starts to set up the Ant task.

To run the example, please perform the following steps:

  1. Use the Ant buildfile build.xml jar to build the article code on the local machine
  2. Copy the jar file to the remote machine
  3. Execute the remote.bat (or rework for a Linux/Unix machine on the remote machine)
  4. Edit the build.xml file to use machine names and ports appropriate to your environment
  5. Use the Ant buildfile build.xml to execute the build and deploy functionality on the local machine


If you've performed the above steps, you should notice that the jar file and build file have been transferred to the remote machine and that the Ant task has been performed on the remote machine.

Conclusion

So, you've read through all of this. What have you learned?

The biggest takeaway from this article should be the importance of a build process to construct your environment in an effective and efficient manner. With that understanding, it is less important that you use Ant or some other homegrown scripting mechanism. However, I feel that Ant is an easy-to-learn platform-independent tool that provides expansion as needed. The XML involved in the buildfile is easy to read and understand, and a large number of already supported commands perform the vast majority of your build tasks without expansion. If you find a limitation, you can expand Ant to include your modifications.

Please review the Ant user guide found in Resources below to expand your understanding of the predefined tasks included with Ant. I hope I have given you a starting point for your future investigation of Ant and have inspired you to incorporate this tool into your development process.

About the author

Michael Cymerman is director of research and development at GroupServe, a Washington, DC-based telecommunications firm that creates Internet-based applications to facilitate group communication.

Read more about Enterprise Java in JavaWorld's Enterprise Java section.

  • Print
  • Feedback

Resources