Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

In order to build Flex applications using Maven you need to prepare the SDK you want to use by converting it into a form Maven can use.

We created the Mavenizer tool, which is part of the flex-utils package. We will probably use this tool in the near future to create Mavenized releases of Flex, but till that is the case you have to manually check out the Mavenizer and run it to create these Mavenized SDKs locally.

...

  1. Do a normal installation of the Flex SDK using the Installer tool (Be sure to check all the checkboxes in order to create a feature complete mavenzied version)
  2. Checkout and build the Mavenizer sources
  3. Run the Mavenizer
  4. (optional) use a deployer to upload the artifacts to a remote Maven repository
  5. Build an application using Flexmojos

Install Flex SDK

  1. Download and Install the Flex Installer (http://flex.apache.org/installer.html)
  2. Install a Flex SDK locally using the Installer (Installation help)

...

  1. Clone the repository:

    Code Block
    themeEmacs
    git clone https://git-wip-us.apache.org/repos/asf/flex-utilities.git utilities

    After this the utilities/maveinzer directory should contain only one "src" directory.

  2. Currently the updated Mavenizer is located in the "mavenizer-refactoringmaster" branch, so we have to switch to that first:  

    Code Block
    git checkout mavenizer-refactoringdevelop

    After this the utilities/mavenizer directory should contain 4 5 sub-directories. This way you know you are on the right branch.

  3. Build the Mavenizer using Maven: 

    Code Block
    cd utilities/mavenizermavenizer 
    mvn clean install

    You will see a lot of log output and hopefully at the end you should be able to read something like this: 

    Code Block
    [INFO] ------------------------------------------------------------------------
    [INFO] BUILD SUCCESS
    [INFO] ------------------------------------------------------------------------
    [INFO] Total time: 8.620s
    [INFO] Finished at: Sat Jul 12 12:41:42 CEST 2014
    [INFO] Final Memory: 40M/230M
    [INFO] ------------------------------------------------------------------------

    Now you have successfully built the mavenizer. The utilities/mavenizer/core/target directory should now contain 2 jar files "core-1.0.0-SNAPSHOT.jar" and "flex-sdk-converter-1.0.0-SNAPSHOT.jar".

Run the Mavenizer

...

Assuming you have downloaded and installed the Flex SDK to the directory c:\Temp\Apache-Flex-SDKs\flex-4.12.1 and you want the Mavenizer to produce the output in c:\Temp\mavenized

 

  1. Create the output directory 

    Code Block
    mkdir c:\Temp\mavenized
  2. Change to the directory where the mavenizer has been created. 

    Code Block
    cd utilities/mavenizer/core/target
  3. Execute the Mavenizer:

    Code Block
    java -cp jar [path-to-the-sdk-converter-jar]/flex-sdk-converter-1.0.0-SNAPSHOT.jar org.apache.flex.utilities.converter.core.SdkConverter "c:\Temp\Apache-Flex-SDKs\flex_sdk_4.12.1-apache" "c:\Temp\mavenized"

    After the execution is finished you should have two directories in the "c:\Temp\mavenized" directory "com" and "org". 

...

  1. Go to the target directory of the deployer you want to use: 

    Code Block
    cd utilities\mavenizer\deployers\aether\target

    This directory should contain two jar files.

  2. Execute the deployer: 

    Code Block
    java -cpjar aether-deployer-1.0.0-SNAPSHOT-full.jar org.apache.flex.utilities.converter.deployer.aether.AetherDeployer "c:\Temp\mavenized" "{url of your remote repository}" "{username}" "{password}"

    Username and password are optional but I pray that you don't have an unsecured remote Maven repository unless you know exactly what you are doing (wink)

  3. You should now see a lot of log output in which the deployer confirms to deploy artifacts to your remote repository.
  4. After the deployment is finished, you can check your repo, if it contains the artifacts by visiting its (The URL you entered as second argument to the deployer).
  5. You're finished ... have fun (smile)

...

  1. Copy the entire content of "c:\Temp\mavenized" to your local repository location (Be sure that the "c:\Temp\mavenized\org" directory is now located at ".m2\repository\org" if your local repository was located at ".m2\repository")
  2. You're finished ... have fun (smile)

 

Build an application using Flexmojos

In earlier versions of Flexmojos you needed only to reference the Flex SDK in the version you wanted. As Flex, AIR and Flash artifacts are no longer linked directly you need to at least reference the Flex SDK as well as the runtime libs you want to use (playerglobal or airglobal). As writing down a complete tutorial on this would exceed the scope of this document by far, I'll simply post two sample pom files, one for an swc and one for an swf (actually they are allmost the same) but they should be enough for you to get the main idea.

Currently the version of Flexmojos able to work with the updated Mavenizer structure is the 7.1.0 version.

SWC Artifact

Code Block
<?xml version="1.0" encoding="UTF-8"?>
<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>my.cool.groupId</groupId>
  <artifactId>swc-artifact</artifactId>
  <version>1.0-SNAPSHOT</version>
  <packaging>swc</packaging>

  <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>
        <dependencies>
          <!-- Without this FM will use the compiler configured in its master pom, which will result in version conflicts -->
          <dependency>
            <groupId>org.apache.flex</groupId>
            <artifactId>compiler</artifactId>
            <version>4.15.0</version>
            <type>pom</type>
          </dependency>
        </dependencies>
      </plugin>
    </plugins>
  </build>

  <dependencies>
    <!-- Flex SDK dependencies -->
    <dependency>
      <groupId>org.apache.flex</groupId>
      <artifactId>framework</artifactId>
      <version>4.15.0</version>
      <type>pom</type>
    </dependency>
    <!-- Flashplayer runtime dependencies -->
    <dependency>
      <groupId>com.adobe.flash.framework</groupId>
      <artifactId>playerglobal</artifactId>
      <version>20.0</version>
      <type>swc</type>
    </dependency>
  </dependencies>

</project>

It is important to note that the two versions of the compiler and the framework have to match each other or you will have trouble. In the above configuration you are using Flexmojos 7.1.0 to compile a Flex 4.15.0 application that is able to run in a FlashPlayer 20.0 and above.

SWF Artifact

 

Code Block
<?xml version="1.0" encoding="UTF-8"?>
<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>my.cool.groupId</groupId>
  <artifactId>swf-artifact</artifactId>
  <version>1.0-SNAPSHOT</version>
  <packaging>swf</packaging>

  <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>
          <sourceFile>ApplicationMain.mxml</sourceFile>
        </configuration>
        <dependencies>
          <!-- Without this FM will use the compiler configured in its master pom, which will result in version conflicts -->
          <dependency>
            <groupId>org.apache.flex</groupId>
            <artifactId>compiler</artifactId>
            <version>4.15.0</version>
            <type>pom</type>
          </dependency>
        </dependencies>
      </plugin>
    </plugins>
  </build>

  <dependencies>
    <!-- Flex SDK dependencies -->
    <dependency>
      <groupId>org.apache.flex</groupId>
      <artifactId>framework</artifactId>
      <version>4.15.0</version>
      <type>pom</type>
    </dependency>
    <!-- Flashplayer runtime dependencies -->
    <dependency>
      <groupId>com.adobe.flash.framework</groupId>
      <artifactId>playerglobal</artifactId>
      <version>20.0</version>
      <type>swc</type>
    </dependency>
  </dependencies>

</project>

In contrast to the SWC Artifact I suggest to add the "sourceFile" attribute to tell the compiler what the main class is. If you don't it will take the first it finds. If there are more than one you could be getting into trouble.