How to build a simple Flex project

POM setup

To create a simple SWF or SWC project, create a directory containing a directory src/main/flex . Place your ActionScript source code there, or create MXML/ActionScript files. Create a POM file in the project root directory and use the repository and pluginRepository elements, so Maven knows how to retrieve the plugin and dependencies. Replace the litteral "PACKAGING-TYPE" with swc or swf , depending on the type of artifact you want to compile.

<project>

    <modelVersion>4.0.0</modelVersion>
    <groupId>my.group.id</groupId>
    <artifactId>my-artifact</artifactId>
    <version>1.0-SNAPSHOT</version>

    <name>My Simple Project</name>
    
    <!-- Replace PACKAGING-TYPE with swf or swc-->
    <packaging>PACKAGING-TYPE</packaging>

    <pluginRepositories>
        <pluginRepository>
            <id>servebox</id>
            <name>ServeBox Plugin Repository</name>
            <url>http://maven.servebox.org/repository</url>
        </pluginRepository>     
    </pluginRepositories>
    <repositories>
        <repository>
            <id>servebox</id>
            <name>ServeBox Plugin Repository</name>
            <url>http://maven.servebox.org/repository</url>
        </repository>   
    </repositories>

    <build>
        ...
        <plugins>
            <plugin>
                <groupId>org.servebox.flex</groupId>
                <artifactId>flex-plugin</artifactId>
                <version>2.3.2</version>
                <extensions>true</extensions>
            </plugin>
        </plugins>
    </build>

</project>

You can use the same goals for swf and swc packaging types :

  • package to build the artifact
  • install to install the artifact to your local repository
  • deploy to deploy the artifact to a remote repository

Note than depending on the packaging type, package, install and deploy are aliases of "flex:makeswf ", "flex:makeswc ", "flex:installswc ", and so on. We encourage you to use the standard lifecycle phase package , install and deploy to be able to build multi-module projects containing swf and swf module (running flex:makeswf on a project with packaging set to swc will fail).

Including the Flex framework dependencies

The only dependency required to build a SWC library that is not using the Flex framework (for example, a utility classes library) is playerglobal.swc . This library is used by the compiler to link Flash Player built-in classes. To build SWC or SWF artifact using the Flex framework, you should specify dependencies to the Flex framework into your POM. Please notice that depending on your project, all dependencies are not required.

<dependencies> 
    ...
    <!-- Version 1.0 corresponds to Flash Player 9.x, 2.0 to Flash Player 10.x -->
    <dependency> 
        <groupId>com.adobe.flash.core</groupId> 
        <artifactId>playerglobal</artifactId> 
        <version>2.0</version> 
        <scope>provided</scope> 
        <type>swc</type> 
    </dependency> 
    <dependency> 
        <groupId>com.adobe.flex.sdkcore</groupId> 
        <artifactId>framework</artifactId> 
        <version>3.2.0.3958</version> 
        <type>swc</type> 
    </dependency> 
    <dependency> 
        <groupId>com.adobe.flex.sdkcore</groupId> 
        <artifactId>flex</artifactId> 
        <version>3.2.0.3958</version> 
        <type>swc</type> 
    </dependency>  
    <dependency> 
        <groupId>com.adobe.flex.sdkcore</groupId> 
        <artifactId>rpc</artifactId> 
        <version>3.2.0.3958</version> 
        <type>swc</type> 
    </dependency> 
    <dependency> 
        <groupId>com.adobe.flex.sdkcore</groupId> 
        <artifactId>utilities</artifactId> 
        <version>3.2.0.3958</version> 
        <type>swc</type> 
    </dependency>
    <!-- LOCALE -->
    <dependency>
        <groupId>com.adobe.flex.locales.en_US</groupId> 
        <artifactId>framework_rb</artifactId> 
        <version>3.2.0.3958</version> 
        <type>swc</type> 
    </dependency> 
    <dependency>
        <groupId>com.adobe.flex.locales.en_US</groupId> 
        <artifactId>rpc_rb</artifactId> 
        <version>3.2.0.3958</version> 
        <type>swc</type> 
    </dependency>
<dependencies>

SWF artifacts

Specify the file to use as the application

The MXML/ActionScript file to be used as the application can be specified using the mxmlFile property. Default value is src/main/flex . Please note you can specify an ActionScript file.

...
    <build>
        ...
        <plugins>
            ...
            <plugin>
                <groupId>org.servebox.flex</groupId>
                <artifactId>flex-plugin</artifactId>
                <version>2.3.2</version>
                <extensions>true</extensions>
                <configuration>
                    <mxmlFile>src/main/flex/MyApplicationClass.mxml</mxmlFile>
                </configuration>
            </plugin>
        </plugins>
    </build>
...

Specify the compile-time locale

The locale is set using the locale property. The dependencies need to be added on the build path, using the dependencies section of your project POM file.

...
    <build>
        ...
        <plugins>
            ...
            <plugin>
                <groupId>org.servebox.flex</groupId>
                <artifactId>flex-plugin</artifactId>
                <version>2.3.2</version>
                <extensions>true</extensions>
                <configuration>
                    <locale>en_US</locale>
                </configuration>
            </plugin>
        </plugins>
    </build>
    ...
    <dependencies>
        ...
        <!-- LOCALE -->
        <dependency>
            <groupId>com.adobe.flex.locales.en_US</groupId>
            <artifactId>framework_rb</artifactId>
            <version>3.1.0.2710</version>
            <type>swc</type>
        </dependency>
        <dependency>
            <groupId>com.adobe.flex.locales.en_US</groupId>
            <artifactId>rpc_rb</artifactId>
            <version>3.1.0.2710</version>
            <type>swc</type>
        </dependency>
    </dependencies>
...

SWC artifacts

Building runtime-shared libraries (RSL)

To force the plugin to compile the RSL for your SWC library, set the makeRSL configuration property to true. The RSL swf file will be created to the output directory. Please note that while using install or deploy goals, if you ask the plugin to generate the RSL for the library, the RSL will also be installed or deployed to the target repositories.

...
    <build>
        ...
        <plugins>
            ...
            <plugin>
                <groupId>org.servebox.flex</groupId>
                <artifactId>flex-plugin</artifactId>
                <version>2.3.2</version>
                <extensions>true</extensions>
                <configuration>
                    <makeRSL>true</makeRSL>
                </configuration>
            </plugin>
        </plugins>
    </build>
...