This Confluence has been LDAP enabled, if you are an ASF Committer, please use your LDAP Credentials to login. Any problems file an INFRA jira ticket please.

Child pages
  • Your first Flex application
Skip to end of metadata
Go to start of metadata

Probably the quickest option to get started is to use of Flexmojos archetypes to setup an initial project.

Execute the following command in order to create an application project:

mvn archetype:generate -DarchetypeGroupId=net.flexmojos.oss -DarchetypeArtifactId=flexmojos-archetypes-application -DarchetypeVersion=7.1.0

You'll probably see the following output on the console. During the process the archetype project will ask you for:

  • groupId
  • artifactId
  • version
  • package

As soon as these are all provided the project is created.

[INFO] Scanning for projects...
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building Maven Stub Project (No POM) 1
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] >>> maven-archetype-plugin:2.3:generate (default-cli) @ standalone-pom >>>
[INFO] 
[INFO] <<< maven-archetype-plugin:2.3:generate (default-cli) @ standalone-pom <<<
[INFO] 
[INFO] --- maven-archetype-plugin:2.3:generate (default-cli) @ standalone-pom ---
[INFO] Generating project in Interactive mode
[INFO] Archetype repository not defined. Using the one from [net.flexmojos.oss:flexmojos-archetypes-application:7.0.1] found in catalog remote
Define value for property 'groupId': : org.apache.flex.examples
Define value for property 'artifactId': : my-first-flex-application
Define value for property 'version':  1.0-SNAPSHOT: : 1.0.0-SNAPSHOT
Define value for property 'package':  org.apache.flex.examples: : 
Confirm properties configuration:
groupId: org.apache.flex.examples
artifactId: my-first-flex-application
version: 1.0.0-SNAPSHOT
package: org.apache.flex.examples
 Y: : y
[INFO] ----------------------------------------------------------------------------
[INFO] Using following parameters for creating project from Old (1.x) Archetype: flexmojos-archetypes-application:7.1.0
[INFO] ----------------------------------------------------------------------------
[INFO] Parameter: groupId, Value: org.apache.flex.examples
[INFO] Parameter: packageName, Value: org.apache.flex.examples
[INFO] Parameter: package, Value: org.apache.flex.examples
[INFO] Parameter: artifactId, Value: my-first-flex-application
[INFO] Parameter: basedir, Value: /Users/christoferdutz/Temp/examples
[INFO] Parameter: version, Value: 1.0.0-SNAPSHOT
[INFO] project created from Old (1.x) Archetype in dir: /Users/christoferdutz/Temp/examples/my-first-flex-application
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 37.154s
[INFO] Finished at: Wed Apr 22 21:05:30 CEST 2015
[INFO] Final Memory: 15M/245M
[INFO] ------------------------------------------------------------------------
[WARNING] The requested profile "apache-release" could not be activated because it does not exist.
bash-3.2$ 

So now you'll find a directory "my-first-flex-application" containing the project.

In order to build the project do this:

cd my-first-flex-application
mvn install

You should see something similar to this:

[INFO] Scanning for projects...
[INFO]                                                                    
                                          `,;':,                :';;;  
                                         `:;''';'             `++'';;, 
                                         :;'''++;'           .+'+''';;;
                              :          ;'''++++''         ,';+++''';'
                  ,. `,  ,. ..: , `,    `'''+++##;'',      ;;'+#+++''''
                 ; ; ; ;; ;`: :,: ; ;    ;'+++;  #;;;;;:::;;;;+  +++'':
                 ; ; : ;; ;., : : ;.     ;;++#    ';;;;;;;;;;+   .+++; 
                 `;: :; `;: :;: , :;`     +;+#    ,;;;:::::;:    ;#+', 
      ;++++:'++      :                ;+,; ++;#    +;::::::;    ,+;;:  
     ++++++,'++                  `++'       +'''`   ;::::::,   +:;;:   
    `+++.   '++    ++++++  +++   +++         '''''   ;:::::   :;;;;    
    +++`    '++   ++++++++ +++` `++:         :'';;;   ;::`   :::::     
    +++     '++  +++'  :++: +++ +++           ;;;;;'        ::::::     
    +++     '++  +++    ++' `+++++`           ;;;;;;:      .:::::`     
    +++++++ '++  +++:::+++.  +++++            ;;;;;;;      ,:::::      
    +++++++ '++  +++++++++   :+++'            ;;;;;;;      ,:::::      
    +++'''  '++  +++;;;:`    +++++            ;;;;;;`      ::::::.     
    +++     '++  +++        +++ +++           ;;;;;:        ::::::     
    +++     :++. ++++   `  :++, ,++;         ''';;.   `..:   ::::;`    
    +++      ++'  +++++++  +++   +++        :''';    ,,,,,:   ;;;;;    
    ;++`     +++   ++++++ +++     +++      .+';+    :,,,,,,:   `';;;   
     ++'                                  `+'''    ::,,,,,:::    ';;'  
     :++                                  #;''    +:::,,,::::    .'':; 
                                         ';;''   ::::::::::::'   ,';;:.
                                         ;;;;''`;+;;::`  .::;;'.,';;;;:
                                        `::;;;''':;;       `;;;'';;;;;;
                                         :::;;;'';:          ;;';;;;;:;
                                         ,:::;;;',            ',;;;;::`
                                          .:::;:.              ;:;;::: 
                                           ::;,                 `,;;`  


[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building my-first-flex-application Flex 1.0.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- maven-resources-plugin:2.7:resources (default-resources) @ my-first-flex-application ---
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] Copying 0 resource
[INFO] 
[INFO] --- flexmojos-maven-plugin:7.1.0:compile-swf (default-compile-swf) @ my-first-flex-application ---
[WARNING] No themes are explicitly defined in the <theme> section or in any scope="theme" dependencies. Flexmojos is now attempting to figure out which themes to include. (to avoid this warning you should explicitly state your theme dependencies)
[WARNING] Adding spark theme because spark.swc was included as a dependency
Writing configuration dump to /Users/christoferdutz/Temp/examples/my-first-flex-application/target/my-first-flex-application-1.0.0-SNAPSHOT-configs.xml
/Users/christoferdutz/Temp/examples/my-first-flex-application/target/my-first-flex-application-1.0.0-SNAPSHOT.swf (602116 bytes)
[INFO] 
[INFO] --- maven-resources-plugin:2.7:testResources (default-testResources) @ my-first-flex-application ---
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory /Users/christoferdutz/Temp/examples/my-first-flex-application/src/test/resources
[INFO] 
[INFO] --- flexmojos-maven-plugin:7.1.0:test-compile (default-test-compile) @ my-first-flex-application ---
[INFO] Compiling test class: [org.apache.flex.examples.TestApp]
[WARNING] No themes are explicitly defined in the <theme> section or in any scope="theme" dependencies. Flexmojos is now attempting to figure out which themes to include. (to avoid this warning you should explicitly state your theme dependencies)
[WARNING] Adding spark theme because spark.swc was included as a dependency
Writing configuration dump to /Users/christoferdutz/Temp/examples/my-first-flex-application/target/test-classes/TestRunner-configs.xml
/Users/christoferdutz/Temp/examples/my-first-flex-application/target/test-classes/TestRunner.swf (893793 bytes)
[INFO] 
[INFO] --- flexmojos-maven-plugin:7.1.0:test-run (default-test-run) @ my-first-flex-application ---
[INFO] Running tests /Users/christoferdutz/Temp/examples/my-first-flex-application/target/test-classes/TestRunner.swf
[INFO] ------------------------------------------------------------------------
[INFO] Tests run: 1, Failures: 0, Errors: 0, Time Elapsed: 0 sec
[INFO] 
[INFO] --- maven-install-plugin:2.5.2:install (default-install) @ my-first-flex-application ---
[INFO] Installing /Users/christoferdutz/Temp/examples/my-first-flex-application/target/my-first-flex-application-1.0.0-SNAPSHOT.swf to /Users/christoferdutz/Maven-Repository/org/apache/flex/examples/my-first-flex-application/1.0.0-SNAPSHOT/my-first-flex-application-1.0.0-SNAPSHOT.swf
[INFO] Installing /Users/christoferdutz/Temp/examples/my-first-flex-application/pom.xml to /Users/christoferdutz/Maven-Repository/org/apache/flex/examples/my-first-flex-application/1.0.0-SNAPSHOT/my-first-flex-application-1.0.0-SNAPSHOT.pom
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 9.826s
[INFO] Finished at: Wed Apr 22 21:15:07 CEST 2015
[INFO] Final Memory: 20M/698M
[INFO] ------------------------------------------------------------------------
[WARNING] The requested profile "apache-release" could not be activated because it does not exist.
bash-3.2$ 

The built application is available in the "target" directory. So if you open the file "my-first-flex-application-1.0.0-SNAPSHOT.swf" with the Flashplayer you'll start your first Flex application.

If you are encountering problems in this step please have a look at the page: Preparing FDKs for Maven builds and Preparing your environment as probably these will help you sort out the problems.

Having a look at the details

<?xml version="1.0" encoding="UTF-8"?>
<!--
    Flexmojos is a set of maven goals to allow maven users to compile, 
	optimize and test Flex SWF, Flex SWC, Air SWF and Air SWC.
    Copyright (C) 2008-2012  Marvin Froeder <marvin@flexmojos.net>

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
-->
<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>org.apache.flex.examples</groupId>
    <artifactId>my-first-flex-application</artifactId>
    <version>1.0.0-SNAPSHOT</version>
    <packaging>swf</packaging>


    <name>my-first-flex-application Flex</name>
 
    <build>
        <sourceDirectory>src/main/flex</sourceDirectory>
        <testSourceDirectory>src/test/flex</testSourceDirectory>
        <plugins>
            <plugin>
                <groupId>net.flexmojos.oss</groupId>
                <artifactId>flexmojos-maven-plugin</artifactId>
                <version>7.1.0</version>
                <extensions>true</extensions>
                <configuration>
                    <debug>true</debug>
                </configuration>
                <dependencies>
                    <dependency>
                        <groupId>org.apache.flex</groupId>
                        <artifactId>compiler</artifactId>
                        <version>4.14.1</version>
                        <type>pom</type>
                    </dependency>
                    <dependency>
                        <groupId>com.adobe</groupId>
                        <artifactId>fontkit</artifactId>
                        <version>1.0</version>
                    </dependency>
                </dependencies>
            </plugin>
        </plugins>
    </build>

    <dependencies>
        <dependency>
            <groupId>org.apache.flex</groupId>
            <artifactId>framework</artifactId>
            <version>4.14.1</version>
            <type>pom</type>
        </dependency>
        <dependency>
            <groupId>com.adobe.flash.framework</groupId>
            <artifactId>playerglobal</artifactId>
            <version>14.0</version>
            <type>swc</type>
        </dependency>

        <dependency>
            <groupId>org.flexunit</groupId>
            <artifactId>flexunit</artifactId>
            <version>4.1.0</version>
            <classifier>flex4</classifier>
            <type>swc</type>
            <scope>test</scope>
        </dependency>
    </dependencies>

</project>

The most im pmortant part here is the declatation of the flexmojos-maven-plugin:

<plugin>
	<groupId>net.flexmojos.oss</groupId>
    <artifactId>flexmojos-maven-plugin</artifactId>
    <version>7.1.0</version>
    <extensions>true</extensions>
 
...
 
<plugin>

This makes the "packaging" type "swf" available to Maven which actually tells Maven how to build a Flex project.

Flexmojos actually doesn't do the compiling, it just configures the Flex compiler and deals with remote controlling this. So in order to compile anything at all, we need to provide a compiler implementation, which is provided by the Apache Flex project:

<dependency>
	<groupId>org.apache.flex</groupId>
    <artifactId>compiler</artifactId>
    <version>4.14.1</version>
    <type>pom</type>
</dependency>

Similar to compiling a Java application a Flex application also has some core classes that provide the core building blocks of any useful application. With a flex application this is split up into two parts:

  • The Flash framework (playerglobal), which represents the API of the Flashplayer
  • The Flex framework, which represents the implementation of the Flex classes which are built on top of the Flashplayer framework

So in order to build a flex application, we need to add references to both of these:

<dependency>
	<groupId>org.apache.flex</groupId>
    <artifactId>framework</artifactId>
    <version>4.14.1</version>
    <type>pom</type>
</dependency>
<dependency>
    <groupId>com.adobe.flash.framework</groupId>
    <artifactId>playerglobal</artifactId>
    <version>14.0</version>
    <type>swc</type>
</dependency>

With these two dependencies in place you would actually be able to start compiling your first flex application.

Unfortunately you would have to use the default maven directory structure, which would have us put resources in "src/main/resources" - which is ok - but we would have to put our Flex code in "src/main/java". We don't want that, so we have to tell Maven where to get the sources from:

        <sourceDirectory>src/main/flex</sourceDirectory>

With flex we are able to also write Unit tests. Similar to the Java world there are several different frameworks available. Flexmojos supports about all of then, but the default however is FlexUnit and therefore it is used in the archetype.

Even if FlexUnit is now part of Apache Flex, Maven artifacts have not yet been released, therefore we have to stick to the old "org.flexunit" artifacts till this is done. 

The FlexUnit support is activated by adding the corresponding dependency to your build: 

        <dependency>
            <groupId>org.flexunit</groupId>
            <artifactId>flexunit</artifactId>
            <version>4.1.0</version>
            <classifier>flex4</classifier>
            <type>swc</type>
            <scope>test</scope>
        </dependency>

Now same with the location of the compile sources, we need to tell Maven where to get the test-sources from, if we don't want to put them in "src/test/java", and this setting is done in the following line:

        <testSourceDirectory>src/test/flex</testSourceDirectory>

The last part, that I didn't actually explain yet is the dependency to: 

                    <dependency>
                        <groupId>com.adobe</groupId>
                        <artifactId>fontkit</artifactId>
                        <version>1.0</version>
                    </dependency>

This is only required if you are planning on embedding Fonts into your application. If you don't need that, you can simply remove that dependency.

Just ignore the "configuration" element for now as this does the finetuning of the compilation and it will be handled by other howtos.

Happy flexing (smile)

  • No labels