Maven - flex plugin

Hi,

I am a poor developer who always look upto Google maharaj whenever I get stuck up in something. Most of the time, it is the blogs which rescue me. I thought, why not to pen down my escapades to help my friends out there. So here is my first blog on my 3 days fight with the maven - flex plugin.

We are building a huge application with EJB 3.0, web services, ESB, and Flex. For repository, we use SVN, for build we use Maven and for continuous integration, we use Hudson. I was assigned the task to build a maven pom.xml for the flex project.

So here are two samples which worked for me.
But before going forward, a few things

  1. I used maven 2.2

  2. I wanted to compile in Flex 3.2, 3.5 and 4.

  3. I am a newbie to both flex and maven. So dont charge on me if I say something wrong. But please do correct me.


  4. Examples / Samples


    1. Sample 1 :- Using net.israfil.mojo
      Here I have a folder which is root folder for my project. Let it be 'project'.
      'project' has 3 subfolders - flex-artifact-id, java-artifact-id and parent-artifact-id.

      parent-artifact-id :- the parent of rest of the project. Its pom.xml looks like

      flex-artifact-id :- The project where flex files are stored. In maven, to use the defaults, we need to place the source files at a specific location. Otherwise we need to write a lot of code to tell the maven engine where our code is placed. So in general, the flex code is stored in src/main/flex folder. The pom.xml file for flex-artifact-id project is



      Here the flex.home variable points to the Flex 3.5 SDK.
      java-artifact-id :- It is a simple java web archieve project. So I wouldnt be explaining anything about it. But the only remaining thing it has to do is to copy the generated swf file and place it in a proper place in web-content from where it would be served.

      To run the build, go to parent-artifact-id folder and issue following command
      mvn clean install.
      This should build the projet.

      N.B.
      1. I could make this work only with the flex SDK 3.5. Working with 4.0 SDK ended in failure. I didnt get enough time to work with it.

      2. The version in the compiler dependency says 4.0.0.10193. We need to check in the mentioned repository whether a compiler for 3.5 exists, and if it does, what is it's exact version.





    2. Sample 2 :- Using Flex mojos
      This is the one we use in our project.

      It's advantage over the previous sample is that building machine does not need to have an SDK. The compiler is itself downloaded by maven. So even a java developer can build this stuff and test his codes (if he forgot to write his unit test classes which he plans to complete when he gets some free time - I bet he would never get it).

      The folder structure is kept essentially the same.

      The parent-artifact-id pom.xml is also the same.

      flex-artifact-id :- The pom.xml is changed. (Hey I need to change something somewhere to create this sample 2).

      Before starting, let us understand that in this case we are working with 3 versions...

      1. The version of flex mojos plugin (flex-mojos.version)

      2. The flex SDK compiler version. (flex.sdk.version)

      3. and The flex version. This is required to obtain flex framework dependencies of the swf file. (flex.version)


      I used versions 3.2 and 3.5. The version 4 needed maven 3, and hence I didn't test it.


      We wouldnt get everything on the maven site. So we need new repositories which can be configured for individual pom.xml. Here is what we used.

      I guess the sonatype repository is not needed. You can remove it once you get everything working.

      Next we use flex mojos plugin. So the build section looks like...

      Note: we have a dependency in the build section. This is not the dependency for our project, but the plugin itself. (This is what I understand. Correct me if I am wrong). The version mentioned here is the version of compiler to be used to compile.

      And finally we have the dependencies ... the lib files required by our project to comile. Essentially these are the framework libs cause we dont have the SDK on our system. So these need to be downloaded.


      This was simple. Wasn't it?

      If you wish to work with other versions, just change in the properties mentioned.

      N.B: Try to keep the mojos plugin version, flex sdk version, flex version as similar.
      E.g. if the flex sdk and flex versions are say 3.5.0.xxxx, keep mojos plugin version as 3.5.0. Otherwise you might get build errors saying - "Unable to .. with pre scanned artifact" or something of this sort.


      I took 3 days to make this simple thing because of the stupid nonsense wensense that our company deploys. It blocked my JARs and I wasnt able to understand what went wrong. It took me 2 days to figure this out.

      The consolidated pom.xml would look like


      java-artifact-id :- Do it yourself :P.
      Here you simply need to copy the generated swf in the required location.


    P.S: How can I paste XML and java codes (in colour coding format as in IDEs) on blogger.com. I wasnt even able to paste my XML codes in it. Using < instead of <>

Comments