Use FDT Folder Path Variables in ANT

 Apr, 06 - 2010   3 comments   Uncategorized

My latest FDT project has a lot of sub-projects. We’ve got a small team of mixed Mac and Windows users, so we don’t want to assume any particular project directory structure if we can help it. The original thinking was to export SWC files for each sub-project, copy them to the appropriate projects for which they are dependencies, wash-rinse-repeat. I’d assumed I’d be able to use FDTs pre/post-build ANT tasks for this, but unfortunately you only get that tab when building to SWF, not for SWCs.

This brought about the idea of putting the entire build routine in ANT, but I hit another roadblock: I want the team members to be able to define folder path variables using the FDT Eclipse Linked Libraries mechanism. To access these:

  • Right-click the FDT project folder >> Properties
  • Choose FDT Build Path
  • Click “Add Linked Libraries…”
  • Click “Add…”

This window lets you manage folder and SWC paths in an abstract way so that build files and classpaths can use the variable instead of a hardcoded path. As long as each team member uses the same variable name, you can share build scripts and complicated classpath settings. All you have to do is tell SVN to ignore the .project file, and everything should be golden.

Ok, so how do you get access to those variables within your ANT scripts? Like this:

<project name=”SampleProject” default=”compileAll” basedir=”.”>
    <!– Import FDT path variables for use as ANT properties –>
    <property file=”${basedir}/../.metadata/.plugins/org.eclipse.core.runtime/.settings/org.eclipse.core.resources.prefs”/>

    <!– etc –>

(I know the wordpress template makes that impossible to read. Cut paste it.) There are some fairly radical assumptions at work here, and I’m not enough of an Eclipse expert to know if it will work in all environments (plus, there are a LOT of variations in environments out there). The idea, however, is that all projects are direct children of the workspace. Therefore, backing up one level from the basedir should put you in the root of the workspace. From there, the path to the aforementioned FDT path variable property file should be as listed. That, of course, assumes that your Eclipse projects are using the default path. If they aren’t, you’re on your own. I wasn’t able to find a workspace variable that gets passed to ANT automatically, but you should be able to set one yourself by going to the menu Run >> External Tools >> External Tools Configurations… In the Arguments textbox, put:


That would let you use the workspace location directly:

    <!– Import FDT path variables for use as ANT properties –>
    <property file=”${workspace_loc}/.metadata/.plugins/org.eclipse.core.runtime/.settings/org.eclipse.core.resources.prefs”/>

You’ll need to become at least passingly familiar with the External Tools dialog because you’ll be visiting it more often than you’d like in order to bypass a minor oversight by the FDT team (IMHO). Go to the JRE tab and switch your Runtime JRE to “Run in the same JRE as the workspace”. If I recall correctly, you’ll have to do this every time you create a new build target (sigh). If you know a better way, by all means leave a comment.

This configuration also assumes that the build.xml file is a direct child of the project folder, ie basedir=”.” If this isn’t the case you should now have enough info to pass the project folder as well. (Hint: try project_loc or project_path)

Once you’ve done this, your FDT path variables can be accessed by prefixing with “pathvariable”. For example:

<echo message=”${pathvariable.AS3SWF_SRC}” />

It took a little Googling on my part to find how to properly export a SWC under ANT without resorting to a complete re-configuration of the classpath. FDT includes an ANT task specifically meant for this purpose. An example looks like:

<target name=”generateSwc2″>

Getting all the variables set up is left as an exercise for the reader. For some help, try Boostworthy’s seminal article.

You should now have all the pieces required to compile and copy SWCs without having paths to specific projects or tools littering your ANT build files. Good luck!

Related articles

 Comments 3 comments

Leave a Reply

Your email address will not be published. Fields with * are mandatory.