Ant build.xml examples?

Started by elias4444, July 11, 2007, 21:14:33

Previous topic - Next topic

elias4444

Well, my project has finally reached the point where it's just getting too darn big to manually compile and package. I've heard that creating an Ant build.xml is the way to go, but I'm a little lost thus far. I was hoping to have a single build.xml file that'll spit out a Mac .app file, a jnlp webstart (with all the jars signed), a Linux directory structure, and a Windows directory structure (so I can quickly package the Linux and Windows versions). I've heard this is all possible, but I don't even know where to begin.

Could anyone who's done this (and I know you're out there) please post their build.xml file for me? Or send it to me if you'd rather it not be made public? I could sure use an example to learn from.
=-=-=-=-=-======-=-=-=-=-=-
http://www.tommytwisters.com

princec

Here's the TreasureTomb build.xml. I don't really suppose it's all that much use to you unless you write your games in a very similar way to me, which is unlikely, but here goes anyway:
<project name="TreasureTomb" default="all" basedir="..">

	<target name="init">
		<!-- Paths -->
		<property name="res" value="res" />
		<property name="src" value="src" />
		<property name="bin" value="bin" />
		<property name="resources-src" value="resources" />
		<property name="libs" value="../Common/libs" />
		<property name="nativelibs" value="../Common/native" />
		<property name="gamecommerce" value="../GameCommerce/bin" />
		<property name="spgltools" value="../SPGLTools/bin" />
		<property name="spgl" value="../Shaven Puppy Game Library/bin" />
		<property name="lwjgl" value="../Common/libs/lwjgl.jar" />
		<property name="lwjglutil" value="../Common/libs/lwjgl_util.jar" />
		<property name="lwjglapplet" value="../LWJGLApplets/bin" />
		<property name="output" value="build" />
		<property name="webstart-output" value="${output}/webstart" />

		<property name="affiliate" value="puppygames" />

		<!-- Signing -->
		<property name="keystore" value="c:/Projects/Common/build/shavenpuppyltd-code-signing-certificate-2006" />
		<property name="alias" value="puppygames"/>
		<property name="storepass" value="as if i'm going to tell you"/>
		<property name="storetype" value="jks"/>

		<!-- MacOS X -->
		<property name="product.name" value="${ant.project.name}" />
		<property name="product.version" value="1.0" />
		<property name="macos-stuff" value="${output}/MacOS" />
		<property name="macbuilds" location="${output}/${product.name}Mac" />
		<property name="gamejar" value="${product.name}.jar" />

		<!-- Tools path -->
		<path id="tools.classpath">
			<pathelement path="${bin}" />
			<!-- Add the /res directory to the path... -->
			<pathelement path="${res}" />
			<pathelement path="${src}" />
			<pathelement path="${diddler}" />
			<pathelement path="${gamecommerce}" />
			<pathelement path="${lwjglapplet}" />
			<pathelement path="${spgltools}" />
			<pathelement path="${spgl}" />
			<pathelement path="${lwjgl}" />
			<pathelement path="${lwjglutil}" />
			<pathelement path="${orbis}" />
			<pathelement path="${java.class.path}" />
		</path>
	</target>

	<!-- Webstart (also used as the basis for MacOS X) -->
	<target name="Webstart Builds" description="Builds the webstart jar and puts it in ${webstart-output}" depends="init">
		<mkdir dir="${webstart-output}" taskname="initialiazing webstart dist folder" />
		<jar destfile="${webstart-output}/${gamejar}" taskname="Create Webstart game jar" compress="true">
			<fileset dir="${bin}">
				<include name="**/**.*" />
			</fileset>
			<fileset dir="${res}">
				<include name="**/**.*" />
			</fileset>
			<fileset dir="${src}">
				<include name="**/**.xml" />
			</fileset>
			<fileset dir="${src}">
				<include name="map.dat" />
			</fileset>
		</jar>
		<signjar jar="${webstart-output}/${gamejar}" alias="${alias}" storepass="${storepass}" storetype="${storetype}" keystore="file:${keystore}" />
	</target>

	<!-- MacOS X Stuff -->
	<target name="clean-osx" depends="init">
		<delete dir="${macbuilds}" />
		<delete>
			<fileset dir="${output}" includes="${product.name}_*_MacOSX.zip"/>
		</delete>
	</target>

	<!-- distribution tasks -->
	<target name="MacOS X Builds" description="Make Mac application bundle" depends="clean-osx">
		<mkdir dir="${macbuilds}/${product.name}.app"/>
		<mkdir dir="${macbuilds}/${product.name}.app/Contents"/>
		<mkdir dir="${macbuilds}/${product.name}.app/Contents/MacOS"/>
		<mkdir dir="${macbuilds}/${product.name}.app/Contents/Resources"/>
		<mkdir dir="${macbuilds}/${product.name}.app/Contents/Resources/Java"/>
		<copy todir="${macbuilds}/${product.name}.app/Contents/MacOS">
			<fileset dir="${macos-stuff}" includes="JavaApplicationStub,mac_launch_fd.sh"/>
		</copy>
		<copy todir="${macbuilds}/${product.name}.app/Contents/Resources">
			<fileset dir="${macos-stuff}" includes="${product.name}.icns"/>
		</copy>
		<copy todir="${macbuilds}/${product.name}.app/Contents/Resources/Java">
			<fileset dir="${webstart-output}">
				<include name="${gamejar}" />
			</fileset>
			<fileset dir="${libs}">
				<include name="common.jar" />
				<include name="gamecommerce.jar" />
				<include name="jorbis.jar" />
				<include name="lwjgl.jar" />
				<include name="lwjgl_util.jar" />
				<include name="spgl-lite.jar" />
				<include name="jinput.jar" />
			</fileset>
			<fileset id="osx.native.files" dir="${nativelibs}">
				<include name="liblwjgl.jnilib" />
				<include name="libjinput-osx.jnilib" />
				<include name="openal.dylib" />
			</fileset>
		</copy>
		<copy preservelastmodified="true" todir="${macbuilds}/${product.name}.app/Contents">
			<fileset dir="${macos-stuff}" includes="Info.plist,PkgInfo"/>
			<filterset>
				<!-- EXECUTABLE is usually the JavaApplicationStub, mac_launch_fd.sh can be
                     used instead to get more file descriptors for applications that need them. -->
				<filter token="EXECUTABLE" value="JavaApplicationStub"/>
				<filter token="PRODUCT" value="${product.name}"/>
				<filter token="VERSION" value="${product.version}"/>
				<filter token="MAIN_CLASS" value="net.puppygames.applet.Launcher"/>
				<!-- This part needs to be customized to include all the jars in the path
                     don't forget to modify Info.plist as needed. -->
				<filter token="JAR_FILE1" value="${gamejar}"/>
				<filter token="JAR_FILE2" value="gamecommerce.jar"/>
				<filter token="JAR_FILE3" value="jorbis.jar"/>
				<filter token="JAR_FILE4" value="common.jar"/>
				<filter token="JAR_FILE5" value="lwjgl.jar"/>
				<filter token="JAR_FILE6" value="lwjgl_util.jar"/>
				<filter token="JAR_FILE7" value="spgl-lite.jar"/>
				<filter token="JAR_FILE8" value="jinput.jar"/>

				<filter token="ICON_FILE" value="${product.name}.icns"/>
				<filter token="AFFILIATE" value="puppygames"/>
			</filterset>
		</copy>
		<zip destfile="${output}/${product.name}_MacOSX.zip">
			<zipfileset dir="${macbuilds}" filemode="644" dirmode="755" prefix="" includes="**/*" excludes="**/JavaApplicationStub,**/*.sh"/>
			<zipfileset dir="${macbuilds}" filemode="755" prefix="" includes="**/JavaApplicationStub,**/*.sh"/>
		</zip>
		
		<!-- Puppygames -->
		<copy overwrite="true" preservelastmodified="true" todir="${macbuilds}/${product.name}.app/Contents">
			<fileset dir="${macos-stuff}" includes="Info.plist,PkgInfo"/>
			<filterset>
				<!-- EXECUTABLE is usually the JavaApplicationStub, mac_launch_fd.sh can be
                     used instead to get more file descriptors for applications that need them. -->
				<filter token="EXECUTABLE" value="JavaApplicationStub"/>
				<filter token="PRODUCT" value="${product.name}"/>
				<filter token="VERSION" value="${product.version}"/>
				<filter token="MAIN_CLASS" value="net.puppygames.applet.Launcher"/>
				<!-- This part needs to be customized to include all the jars in the path
                     don't forget to modify Info.plist as needed. -->
				<filter token="JAR_FILE1" value="${gamejar}"/>
				<filter token="JAR_FILE2" value="gamecommerce.jar"/>
				<filter token="JAR_FILE3" value="jorbis.jar"/>
				<filter token="JAR_FILE4" value="common.jar"/>
				<filter token="JAR_FILE5" value="lwjgl.jar"/>
				<filter token="JAR_FILE6" value="lwjgl_util.jar"/>
				<filter token="JAR_FILE7" value="spgl-lite.jar"/>
				<filter token="JAR_FILE8" value="jinput.jar"/>

				<filter token="ICON_FILE" value="${product.name}.icns"/>
				<filter token="AFFILIATE" value="puppygames"/>
			</filterset>
		</copy>
		<zip destfile="${output}/${product.name}_MacOSX.zip">
			<zipfileset dir="${macbuilds}" filemode="644" dirmode="755" prefix="" includes="**/*" excludes="**/JavaApplicationStub,**/*.sh"/>
			<zipfileset dir="${macbuilds}" filemode="755" prefix="" includes="**/JavaApplicationStub,**/*.sh"/>
		</zip>		


		<delete dir="${macbuilds}" />
	</target>


	<target name="pack-fonts" depends="init">
		<java fork="true" dir="${res}" classname="com.shavenpuppy.jglib.tools.FontConverter">
			<arg value="&quot;04b11-10&quot;" />
			<arg value="&quot;tinyfont.jgfont&quot;" />
			<arg value="256" />
			<arg value="&quot;04b11-16&quot;" />
			<arg value="&quot;smallfont.jgfont&quot;" />
			<arg value="256" />
			<arg value="&quot;04b11-20&quot;" />
			<arg value="&quot;bigfont.jgfont&quot;" />
			<arg value="256" />
			<classpath>
				<path refid="tools.classpath" />
			</classpath>
		</java>
	</target>

	<target name="pack-images" depends="init">
		<java fork="true" dir="." classname="com.shavenpuppy.jglib.tools.ImageConverter">
			<arg value="${resources-src}" />
			<arg value="${res}" />
			<classpath>
				<path refid="tools.classpath" />
			</classpath>
		</java>
		<!-- This bit's specially for converting pre-packed tilesets -->
		<java fork="true" dir="." classname="com.shavenpuppy.jglib.tools.ImageConverter">
			<arg value="${resources-src}/tiles" />
			<arg value="${res}" />
			<classpath>
				<path refid="tools.classpath" />
			</classpath>
		</java>
	</target>

	<target name="pack-textures" depends="init">
		<java fork="true" dir="." classname="com.shavenpuppy.jglib.tools.TexturePacker">
			<arg value="${resources-src}\sprites" />
			<arg value="sprites" />
			<arg value="${res}" />
			<arg value="sprites" />
			<arg value="${src}\sprites.xml" />
			<arg value="${resources-src}\hotspots.txt" />
			<arg value="${resources-src}\styles.txt" />
			<arg value="${resources-src}\excludes.txt" />
			<arg value="512" />
			<arg value="nojpeg" />
			<arg value="linear" />
			<jvmarg value="-ea" />
			<jvmarg value="-Xmx256m" />
			<classpath>
				<path refid="tools.classpath" />
			</classpath>
		</java>
	</target>

	<target name="pack-resources" depends="init">
		<java fork="true" dir="${resources-src}" classname="com.shavenpuppy.jglib.resources.ResourceConverter">
			<arg value="resources.xml" />
			<arg value="../${res}/resources.dat" />
			<classpath>
				<path refid="tools.classpath" />
			</classpath>
		</java>
	</target>

	<target name="pack-sounds" depends="init">
		<java fork="true" dir="${resources-src}" classname="com.shavenpuppy.jglib.tools.SoundPacker">
			<arg value="sounds" />
			<arg value="." />
			<arg value="sounds" />
			<arg value="../src/soundbank.xml" />
			<arg value="44100" />
			<arg value="44100" />
			<arg value="stereo" />
			<jvmarg value="-ea" />
			<classpath>
				<path refid="tools.classpath" />
			</classpath>
		</java>
		<java fork="true" dir="${resources-src}" classname="com.shavenpuppy.jglib.tools.SoundPacker">
			<arg value="sounds" />
			<arg value="." />
			<arg value="sounds-mono" />
			<arg value="../src/soundbank-mono.xml" />
			<arg value="44100" />
			<arg value="44100" />
			<arg value="mono" />
			<jvmarg value="-ea" />
			<classpath>
				<path refid="tools.classpath" />
			</classpath>
		</java>

		<exec dir="${resources-src}" executable="../build/oggenc.exe">
			<arg line="-r -C 2 -q 0 -o ..\${res}\sounds.ogg sounds.raw" />
		</exec>
		<exec dir="${resources-src}" executable="../build/oggenc.exe">
			<arg line="-r -C 1 -q 0 -o ..\${res}\sounds-mono.ogg sounds-mono.raw" />
		</exec>
	</target>

	<target name="pack-music" depends="init">
		<java fork="true" dir="${resources-src}" classname="com.shavenpuppy.jglib.tools.SoundPacker">
			<arg value="music" />
			<arg value="." />
			<arg value="music" />
			<arg value="../src/music.xml" />
			<arg value="44100" />
			<arg value="22050" />
			<arg value="stereo" />
			<arg value="xmlonly" />
			<jvmarg value="-ea" />
			<classpath>
				<path refid="tools.classpath" />
			</classpath>
		</java>
		<exec dir="${resources-src}/music" executable="../build/oggenc.exe">
			<arg line="--downmix --resample 22050 -q 0 -o ..\..\${res}\title.ogg title.wav" />
		</exec>
		<exec dir="${resources-src}/music" executable="../build/oggenc.exe">
			<arg line="--downmix --resample 22050 -q 0 -o ..\..\${res}\hiscores.ogg hiscores.wav" />
		</exec>
		<exec dir="${resources-src}/music" executable="../build/oggenc.exe">
			<arg line="--downmix --resample 22050 -q 0 -o ..\..\${res}\music00.ogg music00.wav" />
		</exec>
	</target>

	<target name="resources"
	        depends="pack-sounds, pack-music, pack-fonts, pack-textures, pack-images, pack-resources"
	/>

	<target name="all">
		<antcall target="resources" />
		<antcall target="Win32 Builds" />
		<antcall target="Webstart Builds" />
		<antcall target="MacOS X Builds" />
	</target>

	<target name="windows" depends="init">
		<mkdir dir="${output}/molebox"
		       taskname="initialiazing molebox folder"
		/>
		<jar destfile="${output}/molebox/${gamejar}"
		     taskname="Create game jar (uncompressed)"
		     compress="false"
		>
			<fileset dir="${bin}">
				<include name="**/**.*" />
			</fileset>
			<fileset dir="${res}">
				<include name="**/**.*" />
			</fileset>
		</jar>
		<copy todir="${output}/molebox" file="${libs}/lwjgl.jar"/>
		<copy todir="${output}/molebox" file="${libs}/lwjgl_util.jar"/>
		<copy todir="${output}/molebox" file="${libs}/common.jar"/>
		<copy todir="${output}/molebox" file="${libs}/gamecommerce.jar"/>
		<copy todir="${output}/molebox" file="${libs}/spgl-lite.jar"/>
		<copy todir="${output}/molebox" file="${libs}/jorbis.jar"/>
		<copy todir="${output}/molebox" file="${libs}/jinput.jar"/>
		<copy todir="${output}/${ant.project.name}" file="${nativelibs}/lwjgl.dll"/>
		<copy todir="${output}/${ant.project.name}" file="${nativelibs}/jinput-dx8.dll"/>
		<copy todir="${output}/${ant.project.name}" file="${nativelibs}/jinput-raw.dll"/>
		<copy todir="${output}/${ant.project.name}" file="${nativelibs}/OpenAL32.dll"/>
		<signjar jar="${output}/molebox/${gamejar}"
	         alias="${alias}"
	         storepass="${storepass}"
	         storetype="${storetype}"
	         keystore="file:${keystore}"
		/>
	</target>

	<target name="molebox" depends="windows">
		<exec dir="${output}/molebox" executable="build/mbox2c.exe" description="Molebox">
			<arg value="${basedir}\build\molebox\${product.name}.exe"/>
		</exec>
	</target>

	<target name="Win32 Builds" description="Make Win32 builds." depends="molebox">
		<exec dir="build" executable="build/makensis.exe" description="Build Win32 Puppygames affiliate version">
			<arg value="${product.name}PUPPYGAMES.nsi"/>
		</exec>
	</target>

</project>

BTW I am an Ant n00b so this script is probably rubbish.

Cas :)

elias4444

QuoteBTW I am an Ant n00b so this script is probably rubbish.
Not at all! I'm even more of a n00b, so it's a great help. I was able to get the Mac OS .app stuff setup yesterday on my own, and I couldn't believe how much nicer it was to just click on the ant script and have everything done automatically! I can't wait to use your example to try and get the rest setup.... one click to make all of my distributions! How exciting!  ;D

Thank you! Thank you!
=-=-=-=-=-======-=-=-=-=-=-
http://www.tommytwisters.com

elias4444

I also wanted to ask... How's molebox working out for you? I've been considering it, but wasn't sure how well it worked for java apps.
=-=-=-=-=-======-=-=-=-=-=-
http://www.tommytwisters.com

princec

Works well, as far as I know. Not sure how it copes with Vista or 98 though.

Cas :)