If you use Flex Builder(now called Flash Builder) for your flex development there are no ‘tricks’ involved, so to speak, in compiling flex apps(Imagine having to pay a fortune and then face things NOT working. Annoying isn’t it?) But when it comes to doing things the open source way, we usually experience deadlocks where we cannot decide which approach to follow and we cry “HELP”.
It’s nothing unusual if that is what happens to you(I experience it all the time
). But what we can do is share the knowledge we have so that we spend less time looking for solutions and more time working on them. That is exactly what I am here for. If you have read my blog entry about “Setting up the Eclipse IDE for Flex“, this tutorial is a direct continuation. Although people who have already set-up their preferred IDE’s will also benefit from this tutorial.
- We will be using the Apache Ant for our compilation tasks. For using the ant build tool, Apache ant run time environment is required to be installed(which is already installed if you have Flex SDK). No work to be done here.
- Running flex action script code on Eclipse requires Java runtime environment to be installed.
- Fire up the terminal(if you are on Linux) and type the following:
sudo apt-get install sun-java6-jdk
and press enter. Just accept the terms and conditions and then , you are good to go. - Otherwise, you also have the option of going over to the official Sun site(now owned by Oracle) and download the latest JDK version. This link might help.
- Fire up the terminal(if you are on Linux) and type the following:
- I am assuming you already have the Eclipse IDE installed on your machine. You may want to take a look at my previous post(link above) for guidelines.
Now, the following part needs to be done for each project you make in your Eclipse. Yes you got that right, for EACH project(Hey! what are you grumbling about? Don’t forget you are getting all of this for free; even reading my blog). Alright let’s look at the steps:
- Make a new Project in your Eclipse.
- Add a .mxml file in this project, say main.mxml
- Type in the following example code(you can write any flex code here. This one’s just an example)::
<?xml version=”1.0″ encoding=”utf-8″?><mx:Application xmlns:mx=”http://www.adobe.com/2006/mxml”><mx:Label text=”Hello World!!”/><mx:Button label=”This button does nothing” /></mx:Application>
Now comes the most important bit: the build.xml file. What we basically want to do is call the mxml compiler located in the flex directory of your hard drive, with the ant build file through eclipse, for compiling our flex project.
- For this create another file named “build.xml” in the same Project. For getting the source code, contact me.
Note that you have to change the 3 paths mentioned in the build.xml(that you will receive),
- path to your mxmlc file. Note:: if you are working in windows, the location will be something like:
- C:\Program Files\AdobeFlex\bin\mxmlc.exe
- path to your output folder
- path to your main .mxml file according to your own settings.
Now to compile your flex app, all you have to do is open the build file in Eclipse, right click somewhere in the body of the file, and then click->Run As->Ant Build. That’s it! Congratulations, you have complied your first Flex app. But a lot more needs to be done to be called a “Flex Developer’. I will be posting some material from time to time on flex and related items. Till then, happy Flex-ing
.
[...] Compiling Flex in Eclipse using Ant [...]