Adding libraries to compilation

Skip to end of metadata
Go to start of metadata

When developing with flex, it is very common to need 3rd party libraries to build more elaborate applications. For example: if an application uses charts, the project will require datavisualization.swc.  If an application needs an SHA1 algorithm, it will require as3corelib, and so on.

Using Adobe's command line compilers (mxmlc and compc) you will use parameters from this list:
-compiler.external-library-path
-compiler.include-libraries
-compiler.library-path
-runtime-shared-library-path

But on flex-mojos those options are not available. If there is no option available, how does one add these libraries?

Simple, following maven way =D

Each required library must be added as a dependency. If you need datavisualization you will add a dependency like this:

<dependency>
  <groupId>com.adobe.flex.sdk</groupId>
  <artifactId>datavisualization</artifactId>
  <version>3.0.0.477</version>
  <type>swc</type>
</dependency>

One big question: How do you discover the dependency's groupId and artifactId?
As with any module in maven, those who created the module must define their groupId and artifactId. Since flex is not very popular with the maven world, it most likely will not be available in any maven repository. If this is the case, you will define your own groupId/artifactId and install on your own repository.

Maven Guide to installing 3rd party JARs

Often times you will have 3rd party JARs that you need to put in your local repository for use in your builds. The JARs must be placed in the local repository in the correct place in order for it to be correctly picked up by Maven. To make this easier, and then error prone, we have provide a goal in the install plug-in which should make this relatively painless. To install a JAR in the local repository use the following command:
mvn install:install-file -Dfile= -DgroupId= -DartifactId= -Dversion= -Dpackaging=

You can follow the same logic for swc libraries.

Example for installing the Data Visualization swc's into Maven.

Download data visualization swc's from here, you need to install them into your maven repo as follows:

  • extract the zip file and cd to the datavisualization_sdk3.3/frameworks/libs and issue the mvn install command.
    mvn install:install-file -DgroupId=com.adobe.flex.framework -DartifactId=datavisualization -Dversion=3.3.0.4852 -Dpackaging=swc -Dfile=datavisualization.swc
    
  • do the same for /frameworks/locale/en_US and run the following commands:
    mvn install:install-file -DgroupId=com.adobe.flex.framework -DartifactId=datavisualization -Dversion=3.3.0.4852 -Dclassifier=en_US -Dpackaging=rb.swc -Dfile=datavisualization_rb.swc
    

You will need the matching dependencies in your pom:

<dependency>
   <groupId>com.adobe.flex.framework</groupId>
   <artifactId>datavisualization</artifactId>
   <version>3.3.0.4852</version>
   <type>swc</type>
 </dependency>
 <dependency>
   <groupId>com.adobe.flex.framework</groupId>
   <artifactId>datavisualization</artifactId>
   <classifier>en_US</classifier>
   <version>3.3.0.4852</version>
   <type>rb.swc</type>
 </dependency>



How do you define how the dependency should be used? If it should be external, how do you get it?
Defining dependency scope:

<dependency>
  <groupId>com.adobe.flex.sdk</groupId>
  <artifactId>datavisualization</artifactId>
  <version>3.0.0.477</version>
  <type>swc</type>
  <scope>external</scope>
</dependency>

Flex-mojos supports 6 scopes:

  • merged: this is the default value, when not defined will assume merged. That means SWC/SWF file will be bigger and self sufficient. Same as -compiler.library-path
  • internal: all dependency content will be included on target SWC/SWF. Biggest compiled file. Same as -compiler.include-libraries
  • external: no dependency content will be included on target SWC/SWF. Smaller compiled file. Makes no sense to use this scope on SWF compilation. Same as -compiler.external-library-path
  • rsl: no dependency content will be inclued on SWC/SWF. But, SWF will have a reference to load it a runtime. Do not use on SWC compilation. Same as -runtime-shared-library-path
  • caching: same as RSL, but uses Adobe signed SWZ files.
  • test: libraries required to run tests. Same as -compiler.include-libraries, but at test template only!
Enter labels to add to this page:
Please wait 
Looking for a label? Just start typing.
  1. Oct 27, 2009

    Matt Hughes says:

    The groupId/artifactId for datavisualization appear to be wrong as they are not ...

    The groupId/artifactId for datavisualization appear to be wrong as they are not in Sonatype repo under those values.  As a matter of fact, I can't find ANY datavisualization swc in the entire repo.  Is this an oversight or is this not included because of license issues?

    ....

     Nevermind I see that you have to install them yourself. Ignore me.