Adding libraries to compilation…

This is a how to post.

When developing with flex, is very common the need for 3rd party libraries to build more elaborated application.  If you wanna charts you must add datavisualization.swc.  If wanna SHA1 algoritm you need as3corelib. So go on…

Using Adobe’s command line compilers (mxmlc and compc) you will use any (or many) parameters from this list:

-compiler.external-library-path
-compiler.include-libraries
-compiler.library-path
-runtime-shared-library-path

But on flex-mojos that options are not available.  If there is no option available, how to add dependencies?

Simple, following maven way =D

Each required library must be add as a dependency.  So, 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 to discovery dependency groupId and artifactId?
Well who make the library must define it. Since maven is not very popular on flex world it provably will not be defined and not available at any maven repository.

When you face this, you will define your own groupId/artifactId and install on your repository by hand.

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.

And how to define how the dependency should be used? If it should be external, how to 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:

    external to -compiler.external-library-path
    internal to -compiler.include-libraries
    merged to -compiler.library-path
    rsl to -runtime-shared-library-path for SWF files
    caching to -runtime-shared-library-path for SWZ files
    test to -compiler.library-path only for test running

If not defined will assumed merged as default.

To read more about flex-mojos scopes click here.

Have a nice weekend every body.

VELO

12 Responses to “Adding libraries to compilation…”

  1. Great common sense post for maven flex developers.

  2. Question : I tried to add this dependency to my pom.xml but it doesn’t work and the maven url does not contain any SWC file
    (http://flex-mojos.googlecode.com/svn/trunk/repository/com/adobe/flex/sdk/datavisualization/3.0.0.3.0.0.477/)

    com.adobe.flex.sdk
    datavisualization
    swc
    external
    3.0.0.3.0.0.477

    Do you have any clue about how to fix this ?

    Thanks

    nicolas

  3. Hi Nicolas…

    That is right. datavisualization isn’t open source. Because of that I will not add datavisualization.swc on flex-mojos maven repository.

    If you need, you must install it by hand.

    You can see instructions to that on dashboard wiki:
    http://code.google.com/p/flex-mojos/wiki/DashboardSamplePom

    VELO

  4. Hi VELO,
    I just testet some external artifacts that I have to add with internal scope and a error message comes up saying: “[ERROR] could not find source for resource bundle automation.”.

    I defined internal scope because I have to use “-compiler.include-libraries” as you wrote above. Here is what I have defined in the pom file:

    com.adobe.flex.sdk
    automation
    swc
    internal

    Is there a way to exclude resource bundles for a particular dependency with internal scope?

    Thanks for your help.

    Regards
    Ingo

  5. Flex compiler is complaining about automation resource-bundle, not flex-mojos.

    If there is an way to make flex compiler don’t worries about it that can be done on flex-mojos. But there is any way to compiler a localized library without providing the resource-bundle? If there is I don’t know it.

    VELO

  6. Hi VELO,
    I just came over that these artifacts have the same behavior as the well known adobe “frameworkswc” artifact. It uses resource bundles from the sdk installation path :( I forgot to add these resource bundles to the repository. So, for anyone using sdk swc files like: airframework.swc, automation.swc, automation_agent.swc, datavisualisation.swc, framework.swc or rpc.swc….

    Do not forget to add those resource bundles to your maven repository :)

    Regards
    Ingo

  7. Hi VELO,

    I’am using lifecycle dataservices in my project and want to include the libs in the compile process. Since the lcds libs are present at runtime in the tomcat container I don’t need to package them, but I need them when compiling.
    I’am using the maven system so I don’t have to add all the libs to the maven repository but just refer to them at the filesystem.

    lcds
    fds
    2.6.2
    swc
    system
    ${lcds.home}/../flex/libs/fds.swc

    So the groupId, artifactId and version are bogus because the only thing that matters is the systemPath. But libs defined this way are not passed to the compile options, so I keep on getting an error during compiling: [Channel definition, mx.messaging.channels.RTMPChannel, can not be found].

    What do you recommend?

    Regards,

    Frank

  8. System scope isn’t supported by flex mojos. Since maven scopes didn’t cover flex compilation scopes.

    http://blog.flex-mojos.info/2008/06/04/scopes/

    VELO

  9. How do I include the swc as RSL in a war? I can get maven to copy all the dependency swc and then package them into a war. But I can’t figure out how to tell maven to extract the swf from the swc (for RSL deployment). Is this possible?
    tks.

  10. Hey,

    Right now that is a manual job done using maven-dependency-plugin.

    Take a look on google group for a sample:

    http://groups.google.com/group/flex-mojos/browse_thread/thread/1aa65f72378eaa89/f53d18f78a5ce320

    VELO

  11. I got another problem. I just try to update to use Flex SDK 3.2 from 3.0.0, and I noticed the group name have changed from com.adobe.flex.sdk to com.adobe.flex.framework.

    I changed all of them in my pom accordingly and then try to compile. Got error essentially telling me resource bundles not found for framework and rpc. Check the svn repo for mojo and find that they have been rename to contain “.rb.”. Did some more googling and I change the “type” for the dependency from “resource-bundle” to “rb.swc”.

    Try compiling again, but it still complains about resource bundle not found for messging and rpc. I add the en_US in the configuration for flex-compiler-mojo as suggested in another link, but it still didn’t work. Can someone please help?

    C:\workspace\kwong_iip_uicore_1_0_0b\iip_uicore\IIPFramework>mvn
    [INFO] Scanning for projects…
    WAGON_VERSION: 1.0-beta-2
    [INFO] ————————————————————————
    [INFO] Building IIP UI Core Framework
    [INFO] task-segment: [install]
    [INFO] ————————————————————————
    [INFO] [iip-core-label-version:version {execution: default}]
    [INFO] [flex-compiler-mojo:compile-swc]
    [INFO] Using configuration file C:\workspace\kwong_iip_uicore_1_0_0b\iip_uicore\
    IIPFramework\target\classes\config.xml
    [WARNING] Nothing expecified to include. Assuming source folders.
    [INFO] Flex compiler configurations:
    -compiler.accessible=false
    -compiler.actionscript-file-encoding UTF-8
    -compiler.allow-source-path-overlap=false
    -compiler.as3=true
    -compiler.debug=false
    -compiler.es=false
    -compiler.external-library-path C:\Documents and Settings\kwong\.m2\repository\F
    luint\Fluint\1.0.0\Fluint-1.0.0.swc C:\Documents and Settings\kwong\.m2\reposito
    ry\Mate\Mate.8.5\Mate-0.8.5.swc C:\Documents and Settings\kwong\.m2\repository
    \renaun\Logger\1.0.1\Logger-1.0.1.swc C:\Documents and Settings\kwong\.m2\reposi
    tory\com\allurent\urlkit\urlkitFlex3.9.2\urlkitFlex3-0.9.2.swc C:\Documents an
    d Settings\kwong\.m2\repository\com\adobe\flex\framework\playerglobal\9-3.2.0.39
    58\playerglobal-9-3.2.0.3958.swc C:\Documents and Settings\kwong\.m2\repository\
    com\adobe\flex\framework\framework\3.2.0.3958\framework-3.2.0.3958.swc
    -compiler.fonts.local-fonts-snapshot C:\workspace\kwong_iip_uicore_1_0_0b\iip_ui
    core\IIPFramework\target\classes\fonts.ser
    -compiler.headless-server=false
    -compiler.include-libraries=
    -compiler.keep-all-type-selectors=false
    -compiler.keep-generated-actionscript=false
    -compiler.library-path C:\Documents and Settings\kwong\.m2\repository\com\adobe\
    flex\framework\flex\3.2.0.3958\flex-3.2.0.3958.swc C:\Documents and Settings\kwo
    ng\.m2\repository\com\adobe\flex\framework\rpc\3.2.0.3958\rpc-3.2.0.3958.swc C:\
    Documents and Settings\kwong\.m2\repository\com\adobe\flex\framework\utilities\3
    .2.0.3958\utilities-3.2.0.3958.swc
    -compiler.locale en_US
    -compiler.optimize=true
    -compiler.source-path C:\workspace\kwong_iip_uicore_1_0_0b\iip_uicore\IIPFramewo
    rk\src C:\workspace\kwong_iip_uicore_1_0_0b\iip_uicore\IIPFramework\src C:\works
    pace\kwong_iip_uicore_1_0_0b\iip_uicore\IIPFramework\locale\en_US
    -compiler.strict=true
    -compiler.theme=
    -compiler.use-resource-bundle-metadata=true
    -compiler.verbose-stacktraces=false
    -compute-digest=true
    -default-background-color 8821927
    -default-frame-rate 24
    -default-script-limits 1000 60
    -default-size 500 375
    flexbuilder3.displayedFirstLaunchMessage true
    -load-config C:\workspace\kwong_iip_uicore_1_0_0b\iip_uicore\IIPFramework\target
    \classes\config.xml
    -metadata.date Jan 2, 2009
    -metadata.language en_US
    -metadata.localized-description en_US UI Core Framework implementation
    -metadata.localized-title en_US IIP UI Core Framework
    -target-player 9.0.0
    -use-network=true
    -verify-digests=true
    [INFO] Loading configuration file C:\workspace\kwong_iip_uicore_1_0_0b\iip_uicor
    e\IIPFramework\target\classes\config.xml
    [WARNING] C:\workspace\kwong_iip_uicore_1_0_0b\iip_uicore\IIPFramework\src\uicor
    e\framework\controls\IIPLinkBarNavigator.mxml:[26,-1] Data binding will not be a
    ble to detect assignments to “layout”.
    [ERROR] could not find source for resource bundle messaging.
    [ERROR] could not find source for resource bundle rpc.

  12. Um, nevermind my previous post. I post it in the wrong thread and I think I know why I got all these problems. The pom I am using is still using 1.0beta of flex mojo, no wonder I am having all these problems!

Discussion Area - Leave a Comment