Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Best Apache Ant Template [closed]

Tags:

java

ant

Every time I create a new project I copy the last project's ant file to the new one and make the appropriate changes (trying at the same time to make it more flexible for the next project). But since I didn't really thought about it at the beginning, the file started to look really ugly.

Do you have an Ant template that can be easily ported in a new project? Any tips/sites for making one?

Thank you.

like image 949
pek Avatar asked Aug 26 '08 14:08

pek


People also ask

Is Apache Ant still used?

Apache Ant is well-established Developers have been using Apache Ant in Java development cycles longer than any other build tool. Apache Ant, which debuted in 2000, is the oldest, still widely used Java build tool.

What is Antcall in build xml?

Description. Call another target within the same buildfile optionally specifying some properties (params in this context). This task must not be used outside of a target . By default, all of the properties of the current project will be available in the new project.

How do I run a specific target in Ant?

To run the ant build file, open up command prompt and navigate to the folder, where the build. xml resides, and then type ant info. You could also type ant instead. Both will work,because info is the default target in the build file.

What is another neat tool?

Another Neat Tool (ANT) is a Java library and command-line application used to drive processes described in build files as targets and extension points dependent upon each other.


2 Answers

An alternative to making a template is to evolve one by gradually generalising your current project's Ant script so that there are fewer changes to make the next time you copy it for use on a new project. There are several things you can do.

Use ${ant.project.name} in file names, so you only have to mention your application name in the project element. For example, if you generate myapp.jar:

<project name="myapp">
   ...
   <target name="jar">
      ...
      <jar jarfile="${ant.project.name}.jar" ...

Structure your source directory structure so that you can package your build by copying whole directories, rather than naming individual files. For example, if you are copying JAR files to a web application archive, do something like:

<copy todir="${war}/WEB-INF/lib" flatten="true">
   <fileset dir="lib" includes="**/*.jar">
</copy>

Use properties files for machine-specific and project-specific build file properties.

<!-- Machine-specific property over-rides -->
<property file="/etc/ant/build.properties" />

<!-- Project-specific property over-rides -->
<property file="build.properties" />

<!-- Default property values, used if not specified in properties files -->
<property name="jboss.home" value="/usr/share/jboss" />
...

Note that Ant properties cannot be changed once set, so you override a value by defining a new value before the default value.

like image 90
Peter Hilton Avatar answered Sep 28 '22 20:09

Peter Hilton


You can give http://import-ant.sourceforge.net/ a try. It is a set of build file snippets that can be used to create simple custom build files.

like image 33
Miguel Pardal Avatar answered Sep 28 '22 20:09

Miguel Pardal