Showing posts with label maven. Show all posts
Showing posts with label maven. Show all posts

Saturday, February 4, 2012

Browser cache, Flex and Maven

A current issue with web application, is the browser cache.

For usual HTML based application, add some meta data is enough:

<meta equiv="CACHE-CONTROL" content="NO-CACHE">
<meta http-equiv="EXPIRES" content="Mon, 01 Jan 1970 00:00:01 GMT">

But with Flex application, it is not so simple.

Flex application are usually wrapped in HTML that allows to detect with the right Flash Player is installed. And if it is not the case, downloading and installing it.

The issue is the Flex SWF name that is specified in the HTML wrapper, makes that browsers put Flex application in cache and don’t reload it.

In the following explanations, the example is a Maven project with a module for the Flex application (using FlexMojos), and a module for the web application.

In the Flex module, the produced SWF file name must be variable, for example, by adding the current version. It is done by giving the final name of the SWF.

In build section, provide the finalName:

<project >
<groupId>my.app</groupId>
<artifactId>myapp-flex-client</artifactId>
<packaging>swf</packaging>
<build>
<finalName>MyFlexApp-${parent.version}</finalName>
<sourceDirectory>src/main/flex</sourceDirectory>
<testSourceDirectory>src/test/flex</testSourceDirectory>
<plugins>
<plugin>
<groupId>org.sonatype.flexmojos</groupId>
<artifactId>flexmojos-maven-plugin</artifactId>
<configuration>
<sourceFile>MyApplication.mxml</sourceFile>
</configuration>
</plugin>
</plugins>
</build>

In the web application, we have to inject the SWF name in the HTML wrapper.

It is done by adding the wrapper goal to Flexmojos plugin.

<groupId>org.sonatype.flexmojos</groupId>
<artifactId>flexmojos-maven-plugin</artifactId>
<version>${flex.mojos.version}</version>
<extensions>true</extensions>
<executions>
<execution>
<phase>generate-resources</phase>
<goals>
<goal>wrapper</goal>
<goal>copy-flex-resources</goal>
</goals>
</execution>
</executions>

Adding it, implies to configure it directly in the plugin. The configuration must contains the artefact to wrap (the Flex application) and the name of the wrapper.

<configuration>
<wrapperArtifact>
<groupId>my.app</groupId>
<artifactId>myapp-flex-client</artifactId>
</wrapperArtifact>
<swf>{build.finalName}</swf>
<htmlName>flashClientWrapper.html</htmlName>
</configuration>

The element defines a variable that is injected in the HTML file. Now, it only remains replace the SWF file name in the wrapper by: ${swf}

Friday, July 16, 2010

Flexmojos et les charts

Une configuration standard du plugin Flexmojos ne permet pas de compiler des charts. La compilation renvoie l'erreur suivante:

[ERROR] Could not resolve <mx:linechart> to a component implementation.

Les dépendances nécessaires ne sont pas disponibles sur un repo Maven. Il faut les ajouter dans le repo local à partir d'une installation du SDK Flex.

Pour commencer, il faut ajouter les dépendances dans le fichier Maven:

<dependency>
<groupid>com.adobe.flex.sdk</groupid>
<artifactid>datavisualization</artifactid>
<type>swc</type>
<scope>merged</scope>
<version>3.2.0.3958</version>
</dependency>
<dependency>
<groupid>com.adobe.flex.sdk</groupid>
<artifactid>datavisualization</artifactid>
<version>3.2.0.3958</version>
<type>rb.swc</type>
<classifier>en_US</classifier>
</dependency>

La seconde dépendances permet d'éviter l'erreur de compilation:

Unable to resolve resource bundle "charts" for locale "en_US".

Ensuite, il faut rajouter les dépendances dans le repo Maven local:

mvn install:install-file -DgroupId=com.adobe.flex.sdk
-DartifactId=datavisualization
-Dversion=3.2.0.3958
-Dpackaging=swc
-Dfile="/Applications/Adobe Flex Builder 3/sdks/3.2.0/frameworks/libs/datavisualization.swc"

Ensuite, il faut rajouter le ressource bundle:

mvn install:install-file -DgroupId=com.adobe.flex.sdk
-DartifactId=datavisualization
-Dversion=3.2.0.3958
-Dclassifier=en_US
-Dpackaging=rb.swc
-Dfile="/Applications/Adobe Flex Builder 3/sdks/3.2.0/frameworks/local/locale/en_US/datavisualization_rb.swc"

Si le scope de l'artifact datavisualization n'est pas mis à merge, l'application compilera, mais l'erreur suivante arrivera à l'exécution:

VerifyError: Error #1014: Class mx.charts::LineChart could not be found.

Il reste encore un problème à résoudre: la licence. Avec la configuration actuelle, les charts vont être affichés avec le message: Trial Visualization.

Il faut configurer le pom pour qu'il utilise la licence à la compilation:

<build>
<sourcedirectory>src/main/flex</sourcedirectory>
<plugins>
<plugin>
<groupid>org.sonatype.flexmojos</groupid>
<artifactid>flexmojos-maven-plugin</artifactid>
<version>3.5.0</version>
<extensions>true</extensions>
<configuration>
<contextroot>/appcontext</contextroot>
<debug>true</debug>
<licenses>
<flexbuilder3>nnnn-nnnn-nnnn-nnnn-nnnn-nnnn</flexbuilder3>
</licenses>
<sourcefile>App.mxml</sourcefile>
<targetplayer>9.0.124</targetplayer>
</configuration>
<dependencies>
<dependency>
<groupid>com.adobe.flex</groupid>
<artifactid>license</artifactid>
<type>jar</type>
<version>3.2.0.3958</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>

La dépendance ne doit être rajouté qu'au plugin, pas au projet.

Le jar nécessaire à la licence n'est pas disponible non plus sur un repo maven, il faut donc l'installer à partir d'une installation Flex avec la commande suivante:

mvn install:install-file
-DgroupId=com.adobe.flex
-DartifactId=license
-Dversion=3.2.0.3958
-Dpackaging=jar
-Dfile="C:\Program Files\Adobe\Flex Builder 3 Plug-in\sdks\3.2.0\lib\license.jar"

Aprés une compilation, les charts s'afficheront sans le message de trial.