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.
[...] command to convert it to an AIR package. I’ve taken this snippet of code from the following blog. Please take a look at that as it explains how this command expects a digital certificate to reside [...]
I’m having trouble with this. When I run “mvn package” I get an inconsistency when the .air file is to be packaged because the .xml (application descriptor) isn’t being copied.
If I have the project open in Eclipse w/ Flex Builder plugin, I have turn on “Build Automatically” for the application descriptor to be build and placed in the build output directory (target). I can’t seem to get the application descriptor to be built and be in the target directory before the application is to be packaged.
Any ideas?
Robin-
Have you configured the resources section of the pom to include the *-app.xml file? It should look something like this (your file name name will likely differ):
<resources>
<resource>
<directory>${basedir}/src/main/flex</directory>
<includes>
<include>Main-app.xml</include>
</includes>
</resource>
...
</resources>
Of course, when you specifically define resources, you’ll also need to tell Maven where to find any others. For example, if you also have resources in the “standard” location (src/main/resources…), you’ll need to assign a resource entry for that as well.
Not sure what’s going on with FlexBuilder. From our experience, the plugin for a standard Eclipse install has more quirks than the stand-alone version of FlexBuilder.
Hope this helps.
-Jim
Thanks for replying Jim.
Actually the solution was simple. The default FlexBuilder project creates a template Main-appl.xml that is then built and put into the build directory at compile time. Replacing the template with the actual version and then using AntRun to copy this to the build directory solved my problem.
Couple of points/questions about your example actually:
1. I develop on both Windows and Linux and I can’t use Sun’s JVM on the Linux box; but the release notes for AIR on Linux say that ADT only works with Sun JVM. So instead of call java in the , have FLEX_HOME/bin in the PATH and just use an of adt. Works fine for me.
2. I have found that I need to have a cert for each platform i.e. to package on Linux I need to have created a self-signed cert on the Linux and use that; but on the Windows box I have to use the self-signed cert created on the Windows machine – doesn’t work otherwise. My CI server is on Linux so it’s fine but occasionally I want to build the .air file on my Windows machine.
3. Your example has:
classes/certs/certificate.p12
The Adobe help docs (http://help.adobe.com/en_US/AIR/1.5/devappsflex/WS5b3ccc516d4fbf351e63e3d118666ade46-7fd6.html) say:
“Note: The keystore file contains the private key used to sign your application. Never include the signing certificate inside the AIR package! If you use wildcards in the ADT command, place the keystore file in a different location so that it is not included in the package. In this example the keystore file, cert.p12, resides in the parent directory.”
I have an Ant task that deletes the cert from the build directory before packaging and then the argument points to the cert in my ${basedir}/src/main/resources/certs/${os.name}/cert.p12
HTML is parsed – the above line should be…
“So instead of call java in the executable, have FLEX_HOME/bin in the PATH and just use an executable of adt and get rid of the java related args. Works fine for me.”
I am still getting the following error when “mvn install” is run in my AIR project folder –
[ERROR] C:\Documents and Settings\narunas\My Documents\workspace\AirMaven\src\main\flex\AirMaven.mxml:[2,-1] Could not resolve to a component implementation.
all other mojos and plug in s are finaly loaded.
I am attempting to at least compile the AIR application using Maven structure to integrate it within the Java backend
Thanks for any suggestions
narunas
Not sure I can be of much help with this, but a couple of things come to mind. I’m assuming the application is building without error in Flex Builder (or the command line compiler). One thing to check is whether you have the entire Flex SDK loaded into your local Maven repository. Hands down, the easiest way to do this is with the “install mojo” that is part of the flex-mojos plugin.
Also, double-check that you have all third-party libraries in your local repository. This error sometimes gets generated when a namespace associated with a custom component (either in your own code or that associated with an external library) cannot be resolved to a package/class.
Thanks for all the info – it finally packages the complete AIR .exe to be distributed….
one point:
I seem to have to manually copy the AIR.swf file to the target directory to be able to package it, changing hte paths in the pom did not help.
Thanks again – this site has been of great help!
Narunas
FWIW, I add air support on flexmojos
http://groups.google.com/group/flex-mojos
VELO