To create a Flex application from a Maven archetype, execute the following command:
$ mvn archetype:generate \ -DarchetypeRepository=http://repository.sonatype.org/content/groups/public\ -DarchetypeGroupId=org.sonatype.flexmojos \ -DarchetypeArtifactId=flexmojos-archetypes-application \ -DarchetypeVersion=3.5.0 [INFO] Scanning for projects... [INFO] Searching repository for plugin with prefix: 'archetype'. [INFO] com.sonatype.maven.plugins: checking for updates from central ... [INFO] [archetype:generate] [INFO] Generating project in Interactive mode [INFO] Archetype defined by properties ... Define value for groupId: : org.sonatype.test Define value for artifactId: : sample-application Define value for version: 1.0-SNAPSHOT: : 1.0-SNAPSHOT Define value for package: org.sonatype.test: : org.sonatype.test Confirm properties configuration: groupId: org.sonatype.test artifactId: sample-library version: 1.0-SNAPSHOT package: org.sonatype.test Y: : Y [INFO] Parameter: groupId, Value: org.sonatype.test [INFO] Parameter: packageName, Value: org.sonatype.test [INFO] Parameter: basedir, Value: /Users/Tim/flex-sample [INFO] Parameter: package, Value: org.sonatype.test [INFO] Parameter: version, Value: 1.0-SNAPSHOT [INFO] Parameter: artifactId, Value: sample-application [INFO] BUILD SUCCESSFUL
If you look in the directory sample-application/ you will see the filesystem shown in Figure 13.5, “Directory Structure for Flex Application Archetype”.
Building an application from the Application archetype produces the following POM.
Example 13.7. POM for Flex Application Archetype
<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.sonatype.test</groupId>
<artifactId>sample-application</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>swf</packaging>
<name>sample-application 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.5.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>com.adobe.flexunit</groupId>
<artifactId>flexunit</artifactId>
<version>0.85</version>
<type>swc</type>
<scope>test</scope>
</dependency>
</dependencies>
<profiles>
<profile>
<id>m2e</id>
<activation>
<property>
<name>m2e.version</name>
</property>
</activation>
<build>
<plugins>
<plugin>
<groupId>org.maven.ide.eclipse</groupId>
<artifactId>lifecycle-mapping</artifactId>
<version>0.9.9-SNAPSHOT</version>
<configuration>
<mappingId>customizable</mappingId>
<configurators>
<configurator
id='org.maven.ide.eclipse.configuration.flex.configurator' />
</configurators>
<mojoExecutions>
<mojoExecution>
org.apache.maven.plugins:maven-resources-plugin::
</mojoExecution>
</mojoExecutions>
</configuration>
</plugin>
</plugins>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>2.4</version>
</plugin>
</plugins>
</pluginManagement>
</build>
</profile>
</profiles>
</project>
The difference between Example 13.7, “POM for Flex Application Archetype” and
Example 13.4, “Project Object Model for Flex Library Archetype” is that the
packaging element is swf instead
of swc. By setting the packaging to
swf, the project will produce a Flex application in
target/sample-application-1.0-SNAPSHOT.swf. The
sample application created by this archetype displays the Text "Hello
World". Main.mxml can be found in
src/main/flex.
Example 13.8. Sample Application Main.mxml
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
<mx:Text text="Hello World!"/>
</mx:Application>
This application also creates a simple FlexUnit test that does
nothing more than print out a trace message. The sample unit test is in
src/test/flex/org/sonatype/test.
Example 13.9. Unit Test for Main.mxml
package org.sonatype.test
{
import flexunit.framework.TestCase;
import Main;
public class TestApp extends TestCase
{
public function testNothing():void
{
//TODO un implemented
trace("Hello test");
}
}
}

