EladElrom.com

Deep Dive Into Technology

Quick tip to generate swc file using ant task with the Java tags

Here’s a quick tip to generate swc file using ant task with the Java tags.
There are plenty of example of using the compc tag like this one below:

<project name="ASDoc build" default="main" >
	<!-- make sure that flexTasks.jar which is located in skd/ant/lib/flexTasks.jar otherwise you'll get an error message -->
	<taskdef resource="flexTasks.tasks" classpath="Jars/flexTasks.jar" />
	<!-- defines all values for the ASDoc compiler -->

    <property file="build.properties" />
    <target name="main" depends="clean-swc-directory, swc-generator" />

    <!-- deletes and recreates the swc directory -->
    <target name="clean-swc-directory" >
       <delete dir="${workspace.dir}/build/swc" />
       <mkdir  dir="${workspace.dir}/build/swc" />
    </target>

	 <!-- generate the swc -->
	<target name="swc-generator" description="Compile the SWC file">
		<compc output="${workspace.dir}/name.swc">
			<include-libraries file="${workspace.dir}/libs" />
			<include-sources dir="${workspace.dir}/src/com" includes="*" />
		</compc>
		<echo>SWC created successfully</echo>
	</target>

</project>

Sometimes you want to generate the entire script using the Java tags. Here’s an example:

        <java jar="${FLEX_HOME}/lib/compc.jar" maxmemory="512m" dir="${FLEX_HOME}/frameworks" fork="true" failonerror="true">
            <arg line="-source-path ${main.src.loc}"/>
            <arg line="-output '${bin.loc}/Name.swc'"/>
            <arg line="-include-libraries '${main.src.loc}/libs'"/>
            <arg line="-include-sources '${main.src.loc}'"/>
		</java>

Took me few hours to figure this out since there aren’t any examples online.

Cheers,
Elad Elrom