The flex-mojos documentation is a bit confusing about the level of support it provides for compiling AIR applications, so I’m making a note about this in order to remind myself how this works.
Building an AIR application using the Flex SDK (as opposed to the Flex Builder IDE) is a two-step process. You first use a command line utility (amxmlc) to compile source code into a swf file. The amxmlc utility is a wrapper around the mxmlc that simply configures mxmlc to use the AIR compiler configuration file. It is also possible to use mxmlc (just as you would for a non-AIR application) and specify this parameter yourself. The second step is to use the adt tool to package the swf as an AIR application and apply a digital certificate to the resulting binary (a requirement for AIR applications). See the AIR developer documentation for more information about building AIR applications using the SDK tools.
Because AIR applications are compiled using the standard Flex compiler, the flex-mojos plugin can handle the compilation phase without any trouble (as an aside, flex-mojos actually uses the flex-oem-compiler rather than mxmlc, but that’s immaterial for this discussion). As far as I can tell, what the plugin does not (yet) support is packaging the resulting swf as an AIR executable and applying the digital certificate. Until the plugin supports this functionality, this step is easily addressed by using another Maven plugin to launch the adt utility.
The plugin documentation states that when compiling an AIR application, the <packaging> element in the pom should be set to aswf, which didn’t work for me. Instead, I set packaging element to swf and configured the flex-mojo plugin as follows.
<plugin>
<groupId>info.flex-mojos</groupId>
<artifactId>flex-compiler-mojo</artifactId>
<version>2.0M9</version>
<extensions>true</extensions>
<configuration>
<sourceFile>Main.mxml</sourceFile>
<configFile>${FLEX_HOME}/frameworks/air-config.xml</configFile>
…
</configuration>
</plugin>
The <configFile> element is the key to making the plugin compile in AIR mode. The FLEX_HOME property is something we ask our developers to define in their Maven settings.xml file. I suspect the need to define this property could be avoided by packaging the Flex SDK tools in a zip file and including them as a dependency in the project, but I just haven’t had time to experiment with that approach yet.
Running Maven with this plugin alone will result in a swf file being generated that can be run with the adl program that comes with the SDK. To package the swf as an AIR application and apply the digital certificate, use the Maven Exec plugin (http://mojo.codehaus.org/exec-maven-plugin/):
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.1-beta-1</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>exec</goal>
</goals>
</execution>
</executions>
<configuration>
<executable>java</executable>
<workingDirectory>${project.build.directory}</workingDirectory>
<arguments>
<argument>-jar</argument>
<argument>${FLEX_HOME}/lib/adt.jar</argument>
<argument>-package</argument>
<argument>-storetype</argument>
<argument>pkcs12</argument>
<argument>-storepass</argument>
<argument>secret</argument>
<argument>-keystore</argument>
<argument>classes/certs/certificate.p12</argument>
<argument>-keypass</argument>
<argument>secret</argument>
<argument>MyApp.air</argument>
<argument>classes/Main-app.xml</argument>
<argument>Main.swf</argument>
</arguments>
</configuration>
</plugin>
This assumes you already have a digital certificate; the SDK includes a utility that you can use to generate a self-signed certificate for use prior to final deployment. One gotcha to note here is that if you don’t supply both the -storepass and the -keypass passwords, the build process will hang. This threw me initially since the only password I had was the one used when creating the digital certificate (and what you specify in the -keypass parameter). I just used the same password for the -storepass parameter and that got it working.
I’m looking forward to the time when flex-mojos supports an end-to-end AIR build. It is an otherwise excellent plugin, and it has worked well for us. In the meantime, this serves as a low-impact workaround.