Building Flex applications

Requirements

Flexmojos does need Maven 3.0.3 and Java 5 or newer to run.

First you need to install Maven. The recommended version is 3.0.3. Make sure to follow the installation instructions at the bottom of the download page. You will also need Java 1.5 or newer.

Confirm that Maven is working properly by typing this at a command line:

mvn -v

 

You should see something similar to this:

$ mvn -v
Maven version: 3.0.3
Java version: 1.6.0_10
OS name: "windows xp" version: "5.1" arch: "x86" Family: "windows"

The Java version needs to be 1.5 or greater, and the OS might be different for you.

Create a new project using archetype

An Archetype is a template for a maven project. Use the following command to create a Flex application:

$ mvn archetype:generate -DarchetypeGroupId=org.sonatype.flexmojos -DarchetypeArtifactId=flexmojos-archetypes-application -DarchetypeVersion=3.1.0

Maven will ask about your project groupId, artifactId and version. Just input the values corresponding to your company, like this:

Define value for property 'groupId': : my.company
Define value for property 'artifactId': : my-project
Define value for property 'version':  1.0-SNAPSHOT: :
Define value for property 'package':  my.company: : my.company.myproject
Confirm properties configuration:
groupId: my.company
artifactId: my-project
version: 1.0-SNAPSHOT
package: my.company.myproject
 Y: : Y

There are other archetypes available here.

There are more information about maven archetypes here.

Default file structure

Once that is done, maven will create a project like this:

my-project
¦   pom.xml
¦
+---src
    +---main
    ¦   +---flex
    ¦   ¦       Main.mxml
    ¦   ¦
    ¦   +---resources
    +---test
        +---flex
            +---my
                +---company
                    +---myproject
                            TestApp.as

Running maven

Run maven at my-project folder:

$ mvn clean install

That will produce a new SWF file at target sub-folder.

my-project
¦   pom.xml
¦
+---src
¦   +---main
¦   ¦   +---flex
¦   ¦   ¦       Main.mxml
¦   ¦   ¦
¦   ¦   +---resources
¦   +---test
¦       +---flex
¦           +---my
¦               +---company
¦                   +---myproject
¦                           TestApp.as
¦
+---target
    +---classes
    ¦
    +---surefire-reports
    ¦
    +---test-classes
    ¦
    +   my-project-1.0-SNAPSHOT.swf

 

Opening my-project-1.0-SNAPSHOT.swf will result in a screen like this: