<p>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.</p>

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

<p>Thank you.</p>

[{'answer_id': 28304, 'author': 'Vinnie', 'author_id': 2890, 'author_profile': 'https://Stackoverflow.com/users/2890', 'pm_score': 0, 'selected': False, 'text': '<p>I used to do exactly the same thing.... then I switched to <a href="http://maven.apache.org/" rel="nofollow noreferrer">maven</a>.  Maven relies on a simple xml file to configure your build and a simple repository to manage your build\'s dependencies (rather than checking these dependencies into your source control system with your code).  </p>\n\n<p>One feature I really like is how easy it is to version your jars - easily keeping previous versions available for legacy users of your library.  This also works to your benefit when you want to upgrade a library you use - like junit.  These dependencies are stored as separate files (with their version info) in your maven repository so old versions of your code always have their specific dependencies available.  </p>\n\n<p>It\'s a better Ant.</p>\n'}, {'answer_id': 28448, 'author': 'Peter Hilton', 'author_id': 2670, 'author_profile': 'https://Stackoverflow.com/users/2670', 'pm_score': 4, 'selected': True, 'text': '<p>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.</p>\n\n<p>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:</p>\n\n<pre><code>&lt;project name="myapp"&gt;\n   ...\n   &lt;target name="jar"&gt;\n      ...\n      &lt;jar jarfile="${ant.project.name}.jar" ...\n</code></pre>\n\n<p>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:</p>\n\n<pre><code>&lt;copy todir="${war}/WEB-INF/lib" flatten="true"&gt;\n   &lt;fileset dir="lib" includes="**/*.jar"&gt;\n&lt;/copy&gt;\n</code></pre>\n\n<p>Use properties files for machine-specific and project-specific build file properties.</p>\n\n<pre><code>&lt;!-- Machine-specific property over-rides --&gt;\n&lt;property file="/etc/ant/build.properties" /&gt;\n\n&lt;!-- Project-specific property over-rides --&gt;\n&lt;property file="build.properties" /&gt;\n\n&lt;!-- Default property values, used if not specified in properties files --&gt;\n&lt;property name="jboss.home" value="/usr/share/jboss" /&gt;\n...\n</code></pre>\n\n<p>Note that Ant properties cannot be changed once set, so you override a value by defining a new value <em>before</em> the default value.</p>\n'}, {'answer_id': 28655, 'author': 'Damien B', 'author_id': 3069, 'author_profile': 'https://Stackoverflow.com/users/3069', 'pm_score': 0, 'selected': False, 'text': '<blockquote>\n  <p>I used to do exactly the same thing.... then I switched to maven.</p>\n</blockquote>\n\n<p>Oh, it\'s Maven 2. I was afraid that someone was still seriously using Maven nowadays. Leaving the jokes aside: if you decide to switch to Maven 2, you have to take care while looking for information, because Maven 2 is a complete reimplementation of Maven, with some fundamental design decisions changed. Unfortunately, they didn\'t change the name, which has been a great source of confusion in the past (and still sometimes is, given the "memory" nature of the web).</p>\n\n<p>Another thing you can do if you want to stay in the Ant spirit, is to use <a href="http://ant.apache.org/ivy/" rel="nofollow noreferrer">Ivy</a> to manage your dependencies.</p>\n'}, {'answer_id': 51071, 'author': 'John Meagher', 'author_id': 3535, 'author_profile': 'https://Stackoverflow.com/users/3535', 'pm_score': 1, 'selected': False, 'text': '<p>If you are working on several projects with similar directory structures and want to stick with Ant instead of going to Maven use the <a href="http://ant.apache.org/manual/Tasks/import.html" rel="nofollow noreferrer">Import task</a>.  It allows you to have the project build files just import the template and define any variables (classpath, dependencies, ...) and have all the <em>real</em> build script off in the imported template.  It even allows overriding of the tasks in the template which allows you to put in project specific pre or post target hooks.  </p>\n'}, {'answer_id': 73631, 'author': 'Scott Stanchfield', 'author_id': 12541, 'author_profile': 'https://Stackoverflow.com/users/12541', 'pm_score': 0, 'selected': False, 'text': "<p>One thing to look at -- if you're using Eclipse, check out the ant4eclipse tasks. I use a single build script that asks for the details set up in eclipse (source dirs, build path including dependency projects, build order, etc).</p>\n\n<p>This allows you to manage dependencies in one place (eclipse) and still be able to use a command-line build to automation.</p>\n"}, {'answer_id': 122219, 'author': 'Mnementh', 'author_id': 21005, 'author_profile': 'https://Stackoverflow.com/users/21005', 'pm_score': 1, 'selected': False, 'text': '<p>I had the same problem and generalized my templates and grow them into in own project: <a href="http://antiplate.origo.ethz.ch/" rel="nofollow noreferrer">Antiplate</a>. Maybe it\'s also useful for you.</p>\n'}, {'answer_id': 2371869, 'author': 'Miguel Pardal', 'author_id': 129497, 'author_profile': 'https://Stackoverflow.com/users/129497', 'pm_score': 3, 'selected': False, 'text': '<p>You can give <a href="http://import-ant.sourceforge.net/" rel="nofollow noreferrer">http://import-ant.sourceforge.net/</a> a try.\nIt is a set of build file snippets that can be used to create simple custom build files.</p>\n'}]
['https://Stackoverflow.com/questions/28202', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/2644/']