If you don't want to build an application but a library to share functionality among multiple applications, you have to create an "swc" library.

Flexmojos comes with an archetype for libraries too. 

In order to create a library application with the archetype, issue the following command:

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

Same as with the application archetype you have to provide some settings. As soon as they are provided, the build should look similar to this:

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-modular-webapp:7.0.1] found in catalog remote
Define value for property 'groupId': : org.apache.flex.examples
Define value for property 'artifactId': : my-first-modular-webapp
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-modular-webapp
version: 1.0.0-SNAPSHOT
package: org.apache.flex.examples
 Y: : y
[INFO] ----------------------------------------------------------------------------
[INFO] Using following parameters for creating project from Archetype: flexmojos-archetypes-modular-webapp:7.1.0
[INFO] ----------------------------------------------------------------------------
[INFO] Parameter: groupId, Value: org.apache.flex.examples
[INFO] Parameter: artifactId, Value: my-first-modular-webapp
[INFO] Parameter: version, Value: 1.0.0-SNAPSHOT
[INFO] Parameter: package, Value: org.apache.flex.examples
[INFO] Parameter: packageInPathFormat, Value: org/apache/flex/examples
[INFO] Parameter: package, Value: org.apache.flex.examples
[INFO] Parameter: version, Value: 1.0.0-SNAPSHOT
[INFO] Parameter: groupId, Value: org.apache.flex.examples
[INFO] Parameter: artifactId, Value: my-first-modular-webapp
[INFO] project created from Archetype in dir: /Users/christoferdutz/Temp/examples/my-first-modular-webapp
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 23.754s
[INFO] Finished at: Wed Apr 22 22:29:03 CEST 2015
[INFO] Final Memory: 15M/245M
[INFO] ------------------------------------------------------------------------
[WARNING] The requested profile "apache-release" could not be activated because it does not exist.

In contrast to the previous two examples, this time a maven project is created that consists of 4 projects:

  • Library in "swc" directory
  • Application using the library in the "swc" directory
  • Web application containing the application in the "war" directory
  • Pom project that joins all projects into one build which is located in the root directory "my-first-modular-webapp"

While "swc" and "swf" are handled by Your first Flex library and Your first Flex application I'll concentrate on the "war" module in this Howto.

In order to build the project do this:

cd my-first-modular-webapp
mvn install

You should see something similar to this:

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


[INFO] ------------------------------------------------------------------------
[INFO] Reactor Build Order:
[INFO] 
[INFO] my-first-modular-webapp
[INFO] swc Library
[INFO] swf Application
[INFO] war
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building my-first-modular-webapp 1.0.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- maven-install-plugin:2.4:install (default-install) @ my-first-modular-webapp ---
[INFO] Installing /Users/christoferdutz/Temp/examples/my-first-modular-webapp/pom.xml to /Users/christoferdutz/Maven-Repository/org/apache/flex/examples/my-first-modular-webapp/1.0.0-SNAPSHOT/my-first-modular-webapp-1.0.0-SNAPSHOT.pom
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building swc Library 1.0.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- maven-resources-plugin:2.7:resources (default-resources) @ swc ---
[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-modular-webapp/swc/src/main/resources
[INFO] 
[INFO] --- flexmojos-maven-plugin:7.1.0:compile-swc (default-compile-swc) @ swc ---
[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-modular-webapp/swc/target/swc-1.0.0-SNAPSHOT-configs.xml
/Users/christoferdutz/Temp/examples/my-first-modular-webapp/swc/target/swc-1.0.0-SNAPSHOT.swc (1845 bytes)
[INFO]
[INFO] --- maven-resources-plugin:2.7:testResources (default-testResources) @ swc ---
[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-modular-webapp/swc/src/test/resources
[INFO] 
[INFO] --- flexmojos-maven-plugin:7.1.0:test-compile (default-test-compile) @ swc ---
[INFO] Compiling test class: [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-modular-webapp/swc/target/test-classes/TestRunner-configs.xml
/Users/christoferdutz/Temp/examples/my-first-modular-webapp/swc/target/test-classes/TestRunner.swf (894162 bytes)
[INFO] 
[INFO] --- flexmojos-maven-plugin:7.1.0:test-run (default-test-run) @ swc ---
[INFO] Running tests /Users/christoferdutz/Temp/examples/my-first-modular-webapp/swc/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) @ swc ---
[INFO] Installing /Users/christoferdutz/Temp/examples/my-first-modular-webapp/swc/target/swc-1.0.0-SNAPSHOT.swc to /Users/christoferdutz/Maven-Repository/org/apache/flex/examples/swc/1.0.0-SNAPSHOT/swc-1.0.0-SNAPSHOT.swc
[INFO] Installing /Users/christoferdutz/Temp/examples/my-first-modular-webapp/swc/pom.xml to /Users/christoferdutz/Maven-Repository/org/apache/flex/examples/swc/1.0.0-SNAPSHOT/swc-1.0.0-SNAPSHOT.pom
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building swf Application 1.0.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- maven-resources-plugin:2.7:resources (default-resources) @ swf ---
[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-modular-webapp/swf/src/main/resources
[INFO] 
[INFO] --- flexmojos-maven-plugin:7.1.0:compile-swf (default-compile-swf) @ swf ---
[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-modular-webapp/swf/target/swf-1.0.0-SNAPSHOT-configs.xml
/Users/christoferdutz/Temp/examples/my-first-modular-webapp/swf/target/swf-1.0.0-SNAPSHOT.swf (602117 bytes)
[INFO] 
[INFO] --- maven-resources-plugin:2.7:testResources (default-testResources) @ swf ---
[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-modular-webapp/swf/src/test/resources
[INFO] 
[INFO] --- flexmojos-maven-plugin:7.1.0:test-compile (default-test-compile) @ swf ---
[INFO] Skipping compiler, test source path doesn't exist.
[INFO] 
[INFO] --- flexmojos-maven-plugin:7.1.0:test-run (default-test-run) @ swf ---
[INFO] Skipping test run. Runner not found: /Users/christoferdutz/Temp/examples/my-first-modular-webapp/swf/target/test-classes
[INFO] 
[INFO] --- maven-install-plugin:2.5.2:install (default-install) @ swf ---
[INFO] Installing /Users/christoferdutz/Temp/examples/my-first-modular-webapp/swf/target/swf-1.0.0-SNAPSHOT.swf to /Users/christoferdutz/Maven-Repository/org/apache/flex/examples/swf/1.0.0-SNAPSHOT/swf-1.0.0-SNAPSHOT.swf
[INFO] Installing /Users/christoferdutz/Temp/examples/my-first-modular-webapp/swf/pom.xml to /Users/christoferdutz/Maven-Repository/org/apache/flex/examples/swf/1.0.0-SNAPSHOT/swf-1.0.0-SNAPSHOT.pom
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building war 1.0.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ war ---
[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-modular-webapp/war/src/main/resources
[INFO] 
[INFO] --- flexmojos-maven-plugin:7.1.0:copy-flex-resources (default) @ war ---
[INFO] 
[INFO] --- maven-compiler-plugin:2.5.1:compile (default-compile) @ war ---
[INFO] No sources to compile
[INFO] 
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ war ---
[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-modular-webapp/war/src/test/resources
[INFO] 
[INFO] --- maven-compiler-plugin:2.5.1:testCompile (default-testCompile) @ war ---
[INFO] No sources to compile
[INFO] 
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ war ---
[INFO] No tests to run.
[INFO] 
[INFO] --- maven-war-plugin:2.2:war (default-war) @ war ---
[INFO] Packaging webapp
[INFO] Assembling webapp [war] in [/Users/christoferdutz/Temp/examples/my-first-modular-webapp/war/target/war-1.0.0-SNAPSHOT]
[INFO] Processing war project
[INFO] Copying webapp resources [/Users/christoferdutz/Temp/examples/my-first-modular-webapp/war/src/main/webapp]
[INFO] Webapp assembled in [25 msecs]
[INFO] Building war: /Users/christoferdutz/Temp/examples/my-first-modular-webapp/war/target/war-1.0.0-SNAPSHOT.war
[INFO] WEB-INF/web.xml already added, skipping
[INFO] 
[INFO] --- maven-install-plugin:2.4:install (default-install) @ war ---
[INFO] Installing /Users/christoferdutz/Temp/examples/my-first-modular-webapp/war/target/war-1.0.0-SNAPSHOT.war to /Users/christoferdutz/Maven-Repository/org/apache/flex/examples/war/1.0.0-SNAPSHOT/war-1.0.0-SNAPSHOT.war
[INFO] Installing /Users/christoferdutz/Temp/examples/my-first-modular-webapp/war/pom.xml to /Users/christoferdutz/Maven-Repository/org/apache/flex/examples/war/1.0.0-SNAPSHOT/war-1.0.0-SNAPSHOT.pom
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary:
[INFO] 
[INFO] my-first-modular-webapp ........................... SUCCESS [0.105s]
[INFO] swc Library ....................................... SUCCESS [7.878s]
[INFO] swf Application ................................... SUCCESS [1.014s]
[INFO] war ............................................... SUCCESS [0.922s]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 10.868s
[INFO] Finished at: Wed Apr 22 22:38:14 CEST 2015
[INFO] Final Memory: 30M/708M
[INFO] ------------------------------------------------------------------------

So if we now look into the "war/target" directory, this contains a file "war-1.0.0-SNAPSHOT.war" which is a fully valid Java war module, which we can conveniantly fire up by using the jetty-maven-plugin, which is already configured in the war module.

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.

In order to test our first Flex web application, all we have to do is execute the following commands:

cd war
mvn jetty:run-exploded

You could use the "run" instead of the "run-exploded", but I have gotten used to using the unpacked war as with this you can simply change the static resources and hit refresh without having to restart the server.

Anyway you will probably see something similar to this:

[INFO] Scanning for projects...
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building war 1.0.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] >>> maven-jetty-plugin:6.1.17:run-exploded (default-cli) @ war >>>
[INFO]                                                                    
                                          `,;':,                :';;;  
                                         `:;''';'             `++'';;, 
                                         :;'''++;'           .+'+''';;;
                              :          ;'''++++''         ,';+++''';'
                  ,. `,  ,. ..: , `,    `'''+++##;'',      ;;'+#+++''''
                 ; ; ; ;; ;`: :,: ; ;    ;'+++;  #;;;;;:::;;;;+  +++'':
                 ; ; : ;; ;., : : ;.     ;;++#    ';;;;;;;;;;+   .+++; 
                 `;: :; `;: :;: , :;`     +;+#    ,;;;:::::;:    ;#+', 
      ;++++:'++      :                ;+,; ++;#    +;::::::;    ,+;;:  
     ++++++,'++                  `++'       +'''`   ;::::::,   +:;;:   
    `+++.   '++    ++++++  +++   +++         '''''   ;:::::   :;;;;    
    +++`    '++   ++++++++ +++` `++:         :'';;;   ;::`   :::::     
    +++     '++  +++'  :++: +++ +++           ;;;;;'        ::::::     
    +++     '++  +++    ++' `+++++`           ;;;;;;:      .:::::`     
    +++++++ '++  +++:::+++.  +++++            ;;;;;;;      ,:::::      
    +++++++ '++  +++++++++   :+++'            ;;;;;;;      ,:::::      
    +++'''  '++  +++;;;:`    +++++            ;;;;;;`      ::::::.     
    +++     '++  +++        +++ +++           ;;;;;:        ::::::     
    +++     :++. ++++   `  :++, ,++;         ''';;.   `..:   ::::;`    
    +++      ++'  +++++++  +++   +++        :''';    ,,,,,:   ;;;;;    
    ;++`     +++   ++++++ +++     +++      .+';+    :,,,,,,:   `';;;   
     ++'                                  `+'''    ::,,,,,:::    ';;'  
     :++                                  #;''    +:::,,,::::    .'':; 
                                         ';;''   ::::::::::::'   ,';;:.
                                         ;;;;''`;+;;::`  .::;;'.,';;;;:
                                        `::;;;''':;;       `;;;'';;;;;;
                                         :::;;;'';:          ;;';;;;;:;
                                         ,:::;;;',            ',;;;;::`
                                          .:::;:.              ;:;;::: 
                                           ::;,                 `,;;`  


[INFO] 
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ war ---
[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-modular-webapp/war/src/main/resources
[INFO] 
[INFO] --- flexmojos-maven-plugin:7.1.0:copy-flex-resources (default) @ war ---
[INFO] Flexmojos 7.1.0
[INFO] 	 GPL License - Version 2.0 (NO WARRANTY) - See COPYRIGHT file
[INFO] 
[INFO] --- maven-compiler-plugin:2.5.1:compile (default-compile) @ war ---
[INFO] No sources to compile
[INFO] 
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ war ---
[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-modular-webapp/war/src/test/resources
[INFO] 
[INFO] --- maven-compiler-plugin:2.5.1:testCompile (default-testCompile) @ war ---
[INFO] No sources to compile
[INFO] 
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ war ---
[INFO] No tests to run.
[INFO] 
[INFO] --- maven-war-plugin:2.4:war (default-war) @ war ---
[INFO] Packaging webapp
[INFO] Assembling webapp [war] in [/Users/christoferdutz/Temp/examples/my-first-modular-webapp/war/target/war-1.0.0-SNAPSHOT]
[INFO] Processing war project
[INFO] Copying webapp resources [/Users/christoferdutz/Temp/examples/my-first-modular-webapp/war/src/main/webapp]
[INFO] Processing overlay [ id org.apache.flex.wrapper:swfobject]
[INFO] Webapp assembled in [211 msecs]
[INFO] Building war: /Users/christoferdutz/Temp/examples/my-first-modular-webapp/war/target/war-1.0.0-SNAPSHOT.war
[INFO]
[INFO] <<< maven-jetty-plugin:6.1.17:run-exploded (default-cli) @ war <<<
[INFO] 
[INFO] --- maven-jetty-plugin:6.1.17:run-exploded (default-cli) @ war ---
[INFO] Configuring Jetty for project: war
[INFO] Logging to org.slf4j.impl.SimpleLogger(org.mortbay.log) via org.mortbay.log.Slf4jLog
[INFO] Context path = /war
[INFO] Tmp directory =  determined at runtime
[INFO] Web defaults = org/mortbay/jetty/webapp/webdefault.xml
[INFO] Web overrides =  none
[INFO] Starting jetty 6.1.17 ...
[INFO] jetty-6.1.17
[INFO] No Transaction manager found - if your webapp requires one, please configure one.
[INFO] Started SelectChannelConnector@0.0.0.0:8080
[INFO] Started Jetty Server

As soon as you read the "Started Jetty Server" your webapp is started and available. As it logged on line above, the server is started on port 8080. The jetty-maven-plugin automatically deploys the application using the artifact-id of the current module. In our case this is "war". So this results in the url: http://localhost:8080/war ... do direct your browser to that url and you'll see something like this:

Ok ... I agree that you will probably not receive an innovation and design prize for that, but at least you have your first Apache Flex based web application up and running. 

Having a look at the details

Let's have a look at the details of the "war" module as the "swf" and "swc" are explained in the other "Your first ..." articles.
The pom of the "war" module is a little more complex, but we'll deal with it step by step.

 

<?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>
    <parent>
    <artifactId>my-first-modular-webapp</artifactId>
    <groupId>org.apache.flex.examples</groupId>
    <version>1.0.0-SNAPSHOT</version>
  </parent>

    <groupId>org.apache.flex.examples</groupId>
    <artifactId>war</artifactId>
    <version>1.0.0-SNAPSHOT</version>
    <packaging>war</packaging>

    <!--
        Properties used in the wrapper template, used by maven-war-plugin to
        perform the filtering.
    -->
    <properties>
        <swf>swf-1.0.0-SNAPSHOT</swf>
        <width>100%</width>
        <height>100%</height>
        <title>My First Application</title>
        <useBrowserHistory>true</useBrowserHistory>
        <bgcolor>white</bgcolor>
        <version_major>10</version_major>
        <version_minor>2</version_minor>
        <version_revision>0</version_revision>
        <expressInstallSwf>expressInstall.swf</expressInstallSwf>
        <application>application</application>
    </properties>

    <build>
        <plugins>
            <!--
                Copy all the flex related resources (SWFs, RSLs, ...)
            -->
            <plugin>
                <groupId>net.flexmojos.oss</groupId>
                <artifactId>flexmojos-maven-plugin</artifactId>
                <version>7.1.0</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>copy-flex-resources</goal>
                        </goals>
                    </execution>
                </executions>
                <dependencies>
                    <dependency>
                        <groupId>org.apache.flex</groupId>
                        <artifactId>compiler</artifactId>
                        <version>4.14.1</version>
                        <type>pom</type>
                    </dependency>
                </dependencies>
            </plugin>
            <!--
                Builds the war and copies the flex default wrapper template.
            -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-war-plugin</artifactId>
                <version>2.4</version>
                <configuration>
                    <overlays>
                        <overlay>
                            <groupId>org.apache.flex.wrapper</groupId>
                            <artifactId>swfobject</artifactId>
                            <type>war</type>
                            <filtered>true</filtered>
                        </overlay>
                    </overlays>
                </configuration>
            </plugin>
            <!--
                Make the war project "runable" by running mvn jetty:run
            -->
            <plugin>
                <groupId>org.mortbay.jetty</groupId>
                <artifactId>maven-jetty-plugin</artifactId>
                <version>6.1.17</version>
            </plugin>
        </plugins>
    </build>

    <dependencies>
        <dependency>
            <groupId>org.apache.flex.examples</groupId>
            <artifactId>swf</artifactId>
            <version>1.0.0-SNAPSHOT</version>
            <type>swf</type>
        </dependency>

        <dependency>
            <groupId>org.apache.flex.wrapper</groupId>
            <artifactId>swfobject</artifactId>
            <version>4.14.1</version>
            <type>war</type>
            <scope>runtime</scope>
        </dependency>
    </dependencies>

</project>

The first thing you should notice, is that the packaging of this module is "war" which activates the lifecycle mapping defined for web modules. The "maven-war-plugin" is automatically activated in order to bundle the finished war application.

But let's first discuss the job of the flexmojos-maven-plugin in this module:

            <plugin>
                <groupId>net.flexmojos.oss</groupId>
                <artifactId>flexmojos-maven-plugin</artifactId>
                <version>7.1.0</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>copy-flex-resources</goal>
                        </goals>
                    </execution>
                </executions>
                <dependencies>
                    <dependency>
                        <groupId>org.apache.flex</groupId>
                        <artifactId>compiler</artifactId>
                        <version>4.14.1</version>
                        <type>pom</type>
                    </dependency>
                </dependencies>
            </plugin>
 
...
 
	<dependency>
	    <groupId>org.apache.flex.examples</groupId>
    	<artifactId>swf</artifactId>
	    <version>1.0.0-SNAPSHOT</version>
    	<type>swf</type>
	</dependency>

With this snippet, we activate the "copy-flex-resources" goal and have it executed in its default lifecycle phase, which is "process-resources". The job of this goal is to take any flex related dependencies in this modules dependency tree and to make sure they are copied to the corresponding war archive. In this case it is only one "swf" dependency, that it has to copy. But as soon as we start working with runtime loaded resource-bundles or RSLs it also creates the correct directories and copies any required resources to places that they can be accessed from the client.

Actually you can ignore the compiler dependency, as this is simply needed because of some legacy dependency of Flexmojos to some of the Flex log-framework classes. It doesn't actually do anything and hopefully it will not be needed in future versions of Flexmojos.

As I already mentioned, the execution of this goal simply makes sure the "swf-1.0.0-SNAPSHOT.swf" file is copied to the "war/target/war-1.0.0-SNAPSHOT" directory, which is the directory where the war archives content is assembled.

After this the maven-war-plugin kicks in. The default configuration makes sure the content of the "war/src/main/webapp" is copied to the war assembly directory too. 

 In our case we want to use the swfobject wrapper of the Flex SDK to load our application. Without it a user would have to access the SWF directly (http://localhost:8080/war/swf-1.0.0-SNAPSHOT.swf), so the wrapper provides an index.html, that checks if a Flashplayer is installed and if it is if it at least satisfies the minimum version requirements. This is done by the following plugin configuration:

    <properties>
        <swf>swf-1.0.0-SNAPSHOT</swf>
        <width>100%</width>
        <height>100%</height>
        <title>My First Application</title>
        <useBrowserHistory>true</useBrowserHistory>
        <bgcolor>white</bgcolor>
        <version_major>10</version_major>
        <version_minor>2</version_minor>
        <version_revision>0</version_revision>
        <expressInstallSwf>expressInstall.swf</expressInstallSwf>
        <application>application</application>
    </properties>


...
 
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-war-plugin</artifactId>
                <version>2.4</version>
                <configuration>
                    <overlays>
                        <overlay>
                            <groupId>org.apache.flex.wrapper</groupId>
                            <artifactId>swfobject</artifactId>
                            <type>war</type>
                            <filtered>true</filtered>
                        </overlay>
                    </overlays>
                </configuration>
            </plugin>


...
 
        <dependency>
            <groupId>org.apache.flex.wrapper</groupId>
            <artifactId>swfobject</artifactId>
            <version>4.14.1</version>
            <type>war</type>
            <scope>runtime</scope>
        </dependency>

The most important part here is the plugin configuration. Here we tell the maven-war-plugin to apply an "overlay" to the output that has been created. You can think of this as extracting the content of another dependency and copying the content over the existing content. In order to add such an overlay, we need to add the overlay artifact as a dependency to the module:

        <dependency>
            <groupId>org.apache.flex.wrapper</groupId>
            <artifactId>swfobject</artifactId>
            <version>4.14.1</version>
            <type>war</type>
            <scope>runtime</scope>
        </dependency>

If this was just static content, we wouldn't need anything else than a dependency of type "war" to have the war-plugin apply the content as an overlay. But in case of the Flex template, there are variables in the static resources, that need to be replaced by values of the current module. Therefore we need to explicitly name the overlay in the plugin configuration and set the "filtered" attribute of that overlay to "true".

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-war-plugin</artifactId>
                <version>2.4</version>
                <configuration>
                    <overlays>
                        <overlay>
                            <groupId>org.apache.flex.wrapper</groupId>
                            <artifactId>swfobject</artifactId>
                            <type>war</type>
                            <filtered>true</filtered>
                        </overlay>
                    </overlays>
                </configuration>
            </plugin>

Having a look at the content of the "index.html" in the template artifact will definitely help understand what's happening now. Here comes a small part of that particular file, but one with a lot of variables to replace:

<script type="text/javascript">
    // For version detection, set to min. required Flash Player version, or 0 (or 0.0.0), for no version detection. 
    var swfVersionStr = "${version_major}.${version_minor}.${version_revision}";
    // To use express install, set to playerProductInstall.swf, otherwise the empty string. 
    var xiSwfUrlStr = "${expressInstallSwf}";
    var flashvars = {};
    var params = {};
    params.quality = "high";
    params.bgcolor = "${bgcolor}";
    params.allowscriptaccess = "sameDomain";
    params.allowfullscreen = "true";
    var attributes = {};
    attributes.id = "${application}";
    attributes.name = "${application}";
    attributes.align = "middle";
    swfobject.embedSWF(
        "${swf}.swf", "flashContent", 
        "${width}", "${height}", 
        swfVersionStr, xiSwfUrlStr, 
        flashvars, params, attributes);
    // JavaScript enabled so display the flashContent div in case it is not replaced with a swf object.
    swfobject.createCSS("#flashContent", "display:block;text-align:left;");
</script>

As you can see there are a lot of variables escaped by "${ ... }". These are the variables that are replaced by mavens filtering. The values that are entered are easily defined as properties in the pom itself:

    <properties>
        <swf>swf-1.0.0-SNAPSHOT</swf>
        <width>100%</width>
        <height>100%</height>
        <title>My First Application</title>
        <useBrowserHistory>true</useBrowserHistory>
        <bgcolor>white</bgcolor>
        <version_major>10</version_major>
        <version_minor>2</version_minor>
        <version_revision>0</version_revision>
        <expressInstallSwf>expressInstall.swf</expressInstallSwf>
        <application>application</application>
    </properties>

So by copying the content of the original file and replacing the variables while processing the content, the following output is created in the war-directories "index.html" file:

<script type="text/javascript">
    // For version detection, set to min. required Flash Player version, or 0 (or 0.0.0), for no version detection. 
    var swfVersionStr = "10.2.0";
    // To use express install, set to playerProductInstall.swf, otherwise the empty string. 
    var xiSwfUrlStr = "expressInstall.swf";
    var flashvars = {};
    var params = {};
    params.quality = "high";
    params.bgcolor = "white";
    params.allowscriptaccess = "sameDomain";
    params.allowfullscreen = "true";
    var attributes = {};
    attributes.id = "application";
    attributes.name = "application";
    attributes.align = "middle";
    swfobject.embedSWF(
        "swf-1.0.0-SNAPSHOT.swf", "flashContent", 
        "100%", "100%", 
        swfVersionStr, xiSwfUrlStr, 
        flashvars, params, attributes);
    // JavaScript enabled so display the flashContent div in case it is not replaced with a swf object.
    swfobject.createCSS("#flashContent", "display:block;text-align:left;");
</script>

After the maven-war-plugin is finished copying stuff, all it has to do, is to zip up the finished war assembly directory and hereby create the "war-1.0.0-SNAPSHOT.war" file.

Actually you wouldn't need to specify the "maven-jetty-plugin" as we could simply run the application by executing "mvn jetty:run" or "mvn jetty:run-exploded", but this way we could provide additional configuration options and generally it's a good idea to mention the plugins you are using. IntelliJ for example only lists the goals of plugins that have been configured in it's maven view. 

 

  • No labels