Open Business is Good For You MobiMap First Release Candidate is Out
Apr 11

[UPDATE] This article series has been reedited on the Adobe Developer Connection. For more information, see this post.

In the previous article of this series, I laid the ground for what will be a step-by-step tutorial about creating a Flex/BlazeDS/Spring/Hibernate project. In this article, I will go into more detail about the creation of the Flex UI for our Todo List application.

Creating a root Maven project

The first issue we have to tackle when creating a Flex/BlazeDS project with Maven is the location of configuration files. Both the Flex compiler and BlazeDS server-side libraries need XML configuration files that describe AMF channels, destinations, adapters and so on. They’re usually called remoting-config.xml and services-config.xml. So if we want to prevent duplicating those configuration files, it could be interesting to put everything into one single war-packaged Maven module. But then there is another issue: this monolithic project setup is not really compliant with Maven standards and mixing Flex and Java compilers in the same module is quite ugly. That’s why I’ve chosen to split the client-side and the server-side into two modules with a root pom-packaged module, at the cost of duplicating configuration files.

So first things first, let’s create the root todolist module. This article series assumes that you have already installed Maven, Java, MySQL and JBoss or Tomcat. If you have not already done so, see their respective website. Now the first thing to do is to create an empty Maven project using the default archetype. To do this, change your working directory to where you want to create the project and run the following command.

mvn -DgroupId=org.epseelon.samples -DartifactId=todolist archetype:create

This command creates a basic JAR project that we will modify to serve as a root module.

  1. Delete the “src” directory in this module
  2. Edit pom.xml and change packaging to “pom” instead of “jar”
  3. Add the following repositories to the POM:
<project>
  …
  <repositories>
    <repository>
      <id>flex-mojos-repository</id>
      <url>http://flex-mojos.googlecode.com/svn/trunk/repository/</url>
      <releases>
        <enabled>true</enabled>
      </releases>
      <snapshots>
        <enabled>false</enabled>
      </snapshots>
    </repository>
    <repository>
      <id>epseelon-repository</id>
      <url>http://m2repo.epseelon.org/</url>
      <releases>
        <enabled>true</enabled>
      </releases>
      <snapshots>
        <enabled>false</enabled>
      </snapshots>
    </repository>
  </repositories>  

  <pluginRepositories>
    <pluginRepository>
      <id>flex-mojos-repository</id>
      <url>http://flex-mojos.googlecode.com/svn/trunk/repository/</url>
      <releases>
        <enabled>true</enabled>
      </releases>
      <snapshots>
        <enabled>false</enabled>
      </snapshots>
    </pluginRepository>
    <pluginRepository>
      <id>epseelon-repository</id>
      <url>http://m2repo.epseelon.org/</url>
      <releases>
        <enabled>true</enabled>
      </releases>
      <snapshots>
        <enabled>false</enabled>
      </snapshots>
    </pluginRepository>
  </pluginRepositories>
</project>

The first repository is the one for the flex-compiler mojo, the second one is my own repository, on which you’ll be able to find blazeds libraries until Adobe releases them in a public repository.

[EDIT]
Finally, since we’re gonna use maven-assembly-plugin and maven-dependency-plugin in submodules, it’s good practice to specify an explicit version for those plugins here. So add the following build section to pom.xml:

<build>
  <pluginManagement>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-dependency-plugin</artifactId>
        <version>2.0</version>
      </plugin>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-assembly-plugin</artifactId>
        <version>2.2-beta-2</version>
      </plugin>
    </plugins>
  </pluginManagement>
</build>

[/EDIT]

Creating a Flex module

We’re going to start with the “easy” part: the Flex module. There are several maven plugins to handle Flex-based projects, namely ServeBox and Israfil. But the last time I tried them, none handled BlazeDS projects, which is why I reported this issue on Adobe issue tracking system. And then one day, a brazilian guy named Velo decided that it was time to act, and he started working on his own Maven plugin. And I have to say that he’s working very fast, because it’s working great, as you will see.

You have to change your working directory to the todolist directory you’ve created above and run the following command:

mvn archetype:create \
-DarchetypeArtifactId=maven-archetype-flex \
-DarchetypeVersion=1.0 \
-DarchetypeGroupId=dk.jacobve.maven.archetypes \
-DgroupId=org.epseelon.samples \
-DartifactId=todolist-ria \
-DpackageName=

This archetype create a Flex project under the root module created above, but it uses israfil mojo by default. So once you’ve created your subproject, you’ll have to replace the israfil plugin configuration with the following one:

<plugin>
  <groupId>info.rvin.mojo</groupId>
  <artifactId>flex-compiler-mojo</artifactId>
  <version>1.0-alpha7</version>
  <extensions>true</extensions>
  <configuration>
    <locales>
      <param>en_US</param>
    </locales>
  </configuration>
</plugin>

You can also delete the properties section, as flex-compiler-mojo uses its own version of the Flex compiler. Last but not least, you have to add the following dependencies section to the POM:

<dependencies>
  <dependency>
    <groupId>com.adobe.flex.sdk</groupId>
    <artifactId>playerglobal</artifactId>
    <version>3.0.0.3.0.0.477</version>
    <type>swc</type>
    <scope>external</scope>
  </dependency>
  <dependency>
    <groupId>com.adobe.flex.sdk</groupId>
    <artifactId>flex</artifactId>
    <version>3.0.0.3.0.0.477</version>
    <type>swc</type>
  </dependency>
  <dependency>
    <groupId>com.adobe.flex.sdk</groupId>
    <artifactId>framework</artifactId>
    <version>3.0.0.3.0.0.477</version>
    <type>swc</type>
  </dependency>
  <dependency>
    <groupId>com.adobe.flex.sdk</groupId>
    <artifactId>framework</artifactId>
    <version>3.0.0.3.0.0.477</version>
    <type>resource-bundle</type>
    <classifier>en_US</classifier>
  </dependency>
  <dependency>
    <groupId>com.adobe.flex.sdk</groupId>
    <artifactId>rpc</artifactId>
    <version>3.0.0.3.0.0.477</version>
    <type>swc</type>
  </dependency>
  <dependency>
    <groupId>com.adobe.flex.sdk</groupId>
    <artifactId>rpc</artifactId>
    <version>3.0.0.3.0.0.477</version>
    <type>resource-bundle</type>
    <classifier>en_US</classifier>
  </dependency>
  <dependency>
    <groupId>com.adobe.flex.sdk</groupId>
    <artifactId>utilities</artifactId>
    <version>3.0.0.3.0.0.477</version>
    <type>swc</type>
  </dependency>
</dependencies>

With those modifications, again from the todolist directory, try to run “mvn install”. Normally, you should get a BUILD SUCCESSFUL message, and you should be able to view todolist/todolist-ria/target/todolist-ria-1.0-SNAPSHOT.swf in Flash Player.

Tadaaaa! That’s it for this second episode: now we have the Flex compiler plugin working on a simple client-only application. In the next episode (now that Luke and Lorelei are back together… woohooo!), we’ll create the server module with Spring and Hibernate. Stay tuned!

PS: Here is Todolist project with just the Flex module

PS II: If someone has a good code beautifier Wordpress plugin to suggest, I’ll take it. I’ve tried WP-Syntax but it sucks with XML code.

Share and Enjoy:
  • description
  • Digg
  • del.icio.us
  • Slashdot
  • e-mail
  • Facebook
  • Google
  • blogmarks
  • Furl
  • StumbleUpon
  • Technorati
  • TwitThis
  • Reddit

26 Responses to “Flex, Spring and BlazeDS: the full stack! (Part 2)”

  1. Flex, Spring and BlazeDS: the full stack! (Part 1) Says:

    [...] Flex, Spring and BlazeDS: the full stack! (Part 2) [...]

  2. Flex-Mojos » Blog Archive » Flex, Spring and BlazeDS: the full stack! (Part 2) Says:

    [...] Today Sébastien publish the second part of his tutorial. http://sebastien-arbogast.com/index.php/2008/04/11/flex-spring-and-blazeds-the-full-stack-part-2/ [...]

  3. Brian Fox Says:

    Rather than duplicate the config files, you can create another module to bundle them up with the assembly plugin and then use the dependency plugin to unpack them where you need them.

    –Brian (Apache Maven PMC member)

  4. Sébastien Says:

    It’s weird. I mean, it would probably work but since Maven is all about integrating best practices, this doesn’t seem like a best practice to me. I would find it more natural if Maven allowed me to define inheritable resources: things like icon images, configuration files that are to be used in several modules of a project, I should be able to put them is src/main/resources in the root module and submodules should have access to this resource. What do you think?

  5. Jeremy Anderson Says:

    I use this for my code listing on my wordpress blog…http://code.google.com/p/syntaxhighlighter/

    It works rather nicely. Here’s a link to the wordpress plugin for it. http://wordpress.org/extend/plugins/syntaxhighlighter-plus/

  6. Sébastien Says:

    Thanks Jeremy. As you can see, it works pretty well, except for keeping spaces and alignment

  7. Sébastien Says:

    Oooops! In fact it doesn’t work, neither pretty, nor well at all. Overflow is completely wrong, all xml elements are lowercased and in Java code, it replaces generics usages by a closing and opening tag (List<TodoItem> becomes List</todoitem><todoitem>). It’s all wrong, I had to deactivate it. And pre doesn’t work very well either in the Wordpress editor: it has a big issue with line feeds when I copy/paste code, it adds blank lines and when I try to remove them, it has a very erratic behaviour. I would have hoped that Wordpress support for code snippet was a little better.

  8. Mike Says:

    Nice. I would share, that I think you can do

    mvn -DgroupId=org.epseelon.samples -DartifactId=todolist archetype:create -Dtype=pom

    where I added -Dtype=pom, then you can get rid of the step to go change the pom type from jar to pom.

  9. Brian Fox Says:

    Inheriting the resources from the parent is an interesting concept, I don’t know if we’ve had that suggestion before. It’s not entirely unprecedented since site stuff does get attached to a parent and is inherited. You should bring this idea to the dev list and we can show you how to write a proposal or maybe someone will run with it.

  10. Sébastien Says:

    Mike, I’ve tried with both type and packaging parameters, and none worked. I always have a jar packaging.

  11. Tim O'Brien Says:

    You can do something similar with the War plugin:

    http://maven.apache.org/plugins/maven-war-plugin/overlays.html

  12. Sébastien Says:

    What to you mean by “something similar”. I know about the overlay technique, but I can’t see how it helps here.

  13. Flex, Spring and BlazeDS: the full stack! (Part 3) Says:

    [...] Flex, Spring and BlazeDS: the full stack! (Part 2) [...]

  14. Bouiaw Says:

    You can see another exemple of a Flex/Spring/GraniteDS (work the same than BlazeDS, but support lazy loading) on http://code.google.com/p/igenko/.

  15. sateesh Says:

    Hi ,

    When i try to install the POM File i am getting the following Error.

    [ERROR]

    [ERROR] BUILD ERROR
    [INFO] ————————————————————————
    [INFO] Plugin could not be found - check that the goal name is correct: Unable to download the artifact from any repository

    Try downloading the file manually from the project website.

    Then, install it using the command:
    mvn install:install-file -DgroupId=info.rvin.mojo -DartifactId=flex-compiler-mojo \
    -Dversion=1.0-alpha7 -Dpackaging=maven-plugin -Dfile=/path/to/file

    info.rvin.mojo:flex-compiler-mojo:maven-plugin:1.0-alpha7

    from the specified remote repositories:
    central (http://repo1.maven.org/maven2)

    info.rvin.mojo:flex-compiler-mojo:maven-plugin:1.0-alpha7

    from the specified remote repositories:
    central (http://repo1.maven.org/maven2)

    [/ERROR]

    When i tried to check whether alpha7 of flex-compiler-mojo i cannot find it on the web site..

    pls let me know what am i doing wrong..

    Sateesh

  16. Sébastien Says:

    It seems that you forgot to add both repositories as explained at the beginning of the article, right after the creation of the root module. Otherwise those repositories would appear in the error message after the central repository.

  17. Flex, Spring and BlazeDS: the full stack! (Epilogue) Says:

    [...] Flex, Spring and BlazeDS: the full stack! (Part 2) [...]

  18. Kavita Says:

    I am getting following error after running mvn -install. Please help.

    [ERROR] BUILD ERROR
    [INFO] ————————————————————————
    [INFO] Internal error in the plugin manager executing goal ‘info.rvin.mojo:flex-compiler-mojo:1.0-alpha7:compile-swf’: U
    nable to find the mojo ‘info.rvin.mojo:flex-compiler-mojo:1.0-alpha7:compile-swf’ in the plugin ‘info.rvin.mojo:flex-com
    piler-mojo’
    info/rvin/mojo/flexmojo/compiler/ApplicationMojo (Unsupported major.minor version 49.0)

  19. Sébastien Says:

    Kavita, what version of the JDK do you have installed on your system?

  20. Kavita Says:

    I have jdk 1.4 but I have JRE 1.6. I did set the JRE_HOME to 1.6. Do you think I need JDK 1.5+?

  21. Sébastien Says:

    Yes, definitely. Maven uses JDK to run and I guess Velo built his plugin with Java 5, so you need at least JDK 5.

  22. sateesh Says:

    Hi,

    If i add the plugin repositories the i am getting the Error:

    Parsing error /home/dpa/kommines/MyWorkspaces/com.lmco.dpa.ui.maven/pom.xml; org.codehaus.plexus.util.xml.pull.XmlPullParserException: Unrecognised tag: ‘pluginrepositories’ (position: START_TAG seen …\n … @32:23)

    That’s the reason why i have commented out these in the first place.

    JDK Version : 1.6.5
    Maven Version : 2.0.5
    OpenSUSE10.3

    Thanks
    Sateesh

  23. sateesh Says:

    Hi,

    Never mind..I moved the pluginrepositories to settings.xml and i am able to build it with out any problems..

    Thanks
    Sateesh

  24. Sébastien Says:

    Sorry, that’s my fault: the case is actually very important: it’s not “pluginrepositories” but “pluginRepositories”. I’ve fixed the code in the article.

  25. Blog Xebia France - Revue de Presse Xebia Says:

    [...] Flex, Spring and BlazeDS: the full stack! (Part 2) [...]

  26. Gal Says:

    Hi,

    any idea how to use flex 4 maven compiler plugin instead of 3?..

    got really confused with the blog.

    THX all

Leave a Reply

Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported
Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported