Getting started

Skip to end of metadata
Go to start of metadata

For now flex is not very popular in maven community and there are not so many repositories for flex libraries and plugins as well.

For those who haven't work with maven at all, it is strongly recommended to read Maven: The Definitive Guide book, at least first two chapters to understand the philosophy of maven. For those who think that he or she is a God of maven then it is recommended to read the same book from chapter 17.

So first we will create a folder structure for our flex project. For this action maven has a great plugin archetype that will create a folder structure and necessary pom.xml files for you.

Flexmojos has its own archetypes for flex application, so here they are:

Create library:
$ mvn archetype:generate -DarchetypeRepository=http://repository.sonatype.org/content/groups/flexgroup -DarchetypeGroupId=org.sonatype.flexmojos -DarchetypeArtifactId=flexmojos-archetypes-library -DarchetypeVersion=[flexmojos targeted version]

Create application:
$ mvn archetype:generate -DarchetypeRepository=http://repository.sonatype.org/content/groups/flexgroup -DarchetypeGroupId=org.sonatype.flexmojos -DarchetypeArtifactId=flexmojos-archetypes-application -DarchetypeVersion=[flexmojos targeted version]

Create modular application:
$ mvn archetype:generate -DarchetypeRepository=http://repository.sonatype.org/content/groups/flexgroup -DarchetypeGroupId=org.sonatype.flexmojos -DarchetypeArtifactId=flexmojos-archetypes-modular-webapp -DarchetypeVersion=[flexmojos targeted version]

We will use the second one flexmojos-archetype-application to create a simple flex application. To run this archetype simply copy it from here and past into a shell, replacing the desired flexmojos version. You'll need to answer some questions before the plugin will create you a folder structure. If everything was good you'll be able to have such a screen:

If you haven't installed Flexmojos yet, maven will do it automatically. All you need to do is configure your Maven instance to point to Sonatype's Nexus repository at http://repository.sonatype.org/content/groups/flexgroup. Detailed instructions can be found here.

It will create a folder structure like this:

So, all your code goes to src/main/flex folder. In this folder you should create your packages and write your code. As you see Flexmojos already has created the main application file Main.mxml. Also there is a test folder for all your tests: src/test/flex/{groupId}, so you can write tests for your application.
But the most interesting part is pom.xml. Let's take a look:

<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/maven-v4_0_0.xsd">

  <modelVersion>4.0.0</modelVersion>
  <groupId>ua.com.xoas</groupId>
  <artifactId>testapp</artifactId>
  <version>1.0</version>
  <packaging>swf</packaging>

  <name>testapp Flex</name>

  <build>
   <sourceDirectory>src/main/flex</sourceDirectory>
   <testSourceDirectory>src/test/flex</testSourceDirectory>
   <plugins>
    <plugin>
     <groupId>org.sonatype.flexmojos</groupId>
     <artifactId>flexmojos-maven-plugin</artifactId>
     <version>3.2.0</version>
     <extensions>true</extensions>
    </plugin>
   </plugins>
  </build>

  <dependencies>
   <dependency>
    <groupId>com.adobe.flex.framework</groupId>
    <artifactId>flex-framework</artifactId>
    <version>3.2.0.3958</version>
    <type>pom</type>
   </dependency>

   <dependency>
    <groupId>org.sonatype.flexmojos</groupId>
    <artifactId>flexmojos-unittest-support</artifactId>
    <version>3.2.0</version>
    <type>swc</type>
    <scope>test</scope>
   </dependency>
  </dependencies>

</project>

If you need to configure your build simply add a configuration element inside of the build element, like this:

<build>
 <sourceDirectory>src/main/flex</sourceDirectory>
 <testSourceDirectory>src/test/flex</testSourceDirectory>
 <plugins>
  <plugin>
    <groupId>org.sonatype.flexmojos</groupId>
    <artifactId>flexmojos-maven-plugin</artifactId>
    <version>3.2.0</version>
    <extensions>true</extensions>
    <configuration>
      <!-- put your configuration options here -->
      <debug>true</debug>
      <allowSourcePathOverlap>true</allowSourcePathOverlap>
    </configuration>
  </plugin>
 </plugins>
</build>

I've added two more options to build:
debug - Turn on generation of debuggable SWFs.
allowSourcePathOverlap - Allow the source-path to have path-elements which contain other path-elements.
Use this link to get a list of available configuration options.

To compile this application you'll need to run:
$ mvn clean install
Flashplayer must be available on system path, otherwise you'll get an error during test phase. If you want to skip test phase run this: mvn install -Dmaven.test.skip=true

The last thing I'd like to pay your attention to is dependencies element. One of the pros of the Flexmojos is that you don't have to install flex-sdk - it will be downloaded automatically and all you need is to add a dependency, in "maven style", to flex-sdk.

<dependency>
 <groupId>com.adobe.flex.framework</groupId>
   <artifactId>flex-framework</artifactId>
   <version>3.2.0.3958</version>
   <type>pom</type>
 </dependency>

Use flexmojos:flexbuilder goal to configure environment files for flexbuilder.

Sonatype redistributes all of the open source Flex and AIR component needed to start developing Flex without having to install versions in your own repository manager. For detailed instructions, see the "Developing with Flexmojos" chapter in Maven: The Definitive Guide.

This was based on MAYBORODA DMITIRY's blog post.

Enter labels to add to this page:
Please wait 
Looking for a label? Just start typing.