Jump to content
  • Advertisement
Sign in to follow this  

Another Neat Tool (ANT): It's better than batch files :)

This topic is 2176 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

So there I was, just a hackin' and a codin' a mod for Minecraft in Eclipse. And at the end, there's a bunch of stuff to do: Run a couple special external tools, relocate a bunch of files into a new folder tree, and then zip them up, add comments to the zip file, and so on. And I had a pretty cool batch file to do all that. Then someone showed me ANT, and I'm sold.


Ant does all the stuff I was doing, but much more elegantly. The tool uses an xml file, usually called build.xml, and it looks like this:

       <!-- do some stuff -->
      <!-- do some other stuff -->

The build.xml that I made for my Minecraft modding endeavors looks like so:[spoiler]

<?xml version="1.0" encoding="UTF-8"?>
<!-- ======================================================================
     Master Build file designed to work for all my minecraft mod projects
     Variables passed in from Eclipse environment:

     ====================================================================== -->

<project name="${project_name}" default="all" basedir="D:/docs/prog/minecraft">

<!-- Manager task, executes all other tasks -->
<target name="all" description="default master task"
   depends="initialize, clean, stage, recompile, reobfuscate, zip, cleanup">
   <echo message="Finished building ${distribution}"/>

<!-- Debugging task, skips recompile/reobfuscate -->
<target name="debug"
   depends="initialize, clean, stage, zip, cleanup">
   <echo message="Rebuilt ${distribution}"/>

<!-- Initialize task -->
<target name="initialize">
   <echo message="Building ${project_name}"/>
   <property name="version" value="Pre-Alpha"/>

   <!-- Files and Folders -->
   <property name="MOD"         location="${basedir}/mods/${project_name}"/>
   <property name="anglewyrm" location="${basedir}/../anglewyrm"/>
   <property name="MCP"         location="${basedir}/MCP152"/>
   <property name="staging_area" location="${MCP}/src/minecraft/mods/${project_name}"/>
   <property name="reobf"     location="${MCP}/reobf/minecraft"/>
   <property name="python"     location="${MCP}/runtime/bin/python/python_mcp.exe"/>
      <format property="dateStamp" pattern="dd-MMM-yyyy"/>
   <property name="distribution" location="${basedir}/distribution/${project_name}-${dateStamp}.zip"/>

<!-- Clean -->
<target name="clean">
   <echo message="Preparing empty staging area"/>
   <delete dir="${staging_area}"/>
   <delete file="${distribution}"/>
   <mkdir dir="${staging_area}"/>

<!-- Stage source -->
<target name="stage">
   <echo message="Staging source to ${staging_area}"/>
   <filter token="VERSION" value="${version}"/>
   <filter token="RELEASE_DATE" value="${dateStamp}"/>
   <copy todir="${staging_area}" filtering="true">
      <fileset dir="${MOD}" excludes="textures/**"/>
   <copy todir="${staging_area}/textures" filtering="false">
      <fileset dir="${MOD}/textures" />
   <copy todir="${staging_area}/../..">
      <fileset file="${staging_area}/mcmod.info"/>
   <delete file="${staging_area}/mcmod.info"/>

<!-- Run recompile -->
<target name="recompile" description="MCP recompile" >
   <exec executable="${python}" dir="${MCP}" >
      <arg value="runtime/recompile.py" />
      <arg value="%*" />

<!-- Run reobfuscate -->
<target name="reobfuscate" description="MCP reobfuscate" >
   <exec executable="${python}" dir="${MCP}" >
      <arg value="runtime/reobfuscate.py" />
      <arg value="%*" />

<!-- Zip -->
<target name="zip" description="Zip up the mod">
   <echo message="Creating ${distribution}" />
   <zip destfile="${distribution}">
      <zipfileset dir="${reobf}" />
      <zipfileset dir="${staging_area}/textures" prefix="mods/${project_name}/textures" />
      <zipfileset dir="${staging_area}/../.." includes="mcmod.info" />

<!-- Cleanup -->
<target name="cleanup">
   <echo message="Removing temporary files"/>
   <!-- <delete dir="${staging_area}"/> -->




It can do advanced stuff, like substituting a token string during a copy operation. Within my source files is @VERSION@, but when copied by the build.xml, that string gets replaced.

Edited by AngleWyrm

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!