Le Touilleur Express

  • Accueil
  • A propos de l’auteur
  • A propos du Touilleur Express
Next Previous

Flex, BlazeDS, Spring, Hibernate all together with Maven

8 juillet, 2008

Note: first post ever in english but I really thought it would matter.

For those who wants to play with Flex, BlazeDS, Spring, Hibernate using a set of Maven projet, François le Droff wrote a good article. He managed to set-up a nice environment that was really helpfull for me when I started to add maven support to my own project.

Read http://blogs.adobe.com/francoisledroff/2008/05/my_blazeds_xdoclet_spring_hibe.html

However my project use Charts and when I tried to add support for Charts, it doesn’t compile anymore with Maven. I managed to fix various issues and I will report there how to make it work.

Add new mirror to your maven configuration

First, as explained on its post, add its repository to your maven configuration file
Here is my settings.xml :

<settings>
    <localRepository>>/Users/nicolasmartignole/.m2/repository</localRepository>
    <offline>false</offline>

    <proxies>
    </proxies>

    <servers>
    </servers>

    <mirrors>
        <mirror>
            <id>ibiblio</id>
            <mirrorOf>central</mirrorOf>
            <name>Ibiblio central repos.</name>
            <url>http://www.ibiblio.org/maven2</url>
        </mirror>
    </mirrors>

    <profiles>
        <profile>
            <id>defaultProfile</id>
            <activation>
                <activeByDefault>true</activeByDefault>
            </activation>

            <repositories>
                <repository>
                    <id>fna-repository</id>
                    <name>fna-repository</name>
                    <url>http://fna.googlecode.com/svn/trunk/fna/fna_m2_repository/</url>
                    <releases>
                        <enabled>true</enabled>
                    </releases>
                    <snapshots>
                        <enabled>false</enabled>
                    </snapshots>
                </repository>
            </repositories>

            <pluginRepositories>
                <pluginRepository>
                    <id>fna-repository</id>
                    <name>fna-repository</name>
                    <url>http://fna.googlecode.com/svn/trunk/fna/fna_m2_repository/</url>
                    <releases>
                        <enabled>true</enabled>
                    </releases>
                    <snapshots>
                        <enabled>false</enabled>
                    </snapshots>
                </pluginRepository>
            </pluginRepositories>
        </profile>
    </profiles>
</settings>

Create a simple project from scratch

Now it’s time to create your first maven project with Flex. I will call my new project « Lombok » and it will be part of « Treck » which is my company name.


mvn archetype:create
-DarchetypeGroupId=com.droff
-DarchetypeArtifactId=blazeds-xdoclet-spring-hibernate-archetype
-DarchetypeVersion=1.0
-DgroupId=org.treck
-DartifactId=lombok

Create a new IDEA IntelliJ project

Go to the new created folder (cd lombok) and type-in

mvn idea:idea -DjdkName=1.5

This will create a new IntelliJ Project.
You can also create a new Eclipse project with :

 mvn eclipse:eclipse

Compile time !

It’s now time to build the first project. There’s nothing special here since François’s project come with a nice CRUD application that works with HSQL database and Hibernate.

Simply type « mvn install » and wait for compilation

Deploy time

Once your project has been compiled you can now start the local Jetty servlet container. BlazeDS has already been configured for you with a simple amf service.

Enter

cd java_webapp
mvn jetty:run-exploded

If everything went well you should see something similar to the folowing output :

...
...
6 juil. 2008 09:34:50 org.springframework.orm.hibernate3.HibernateTransactionManager afterPropertiesSet
INFO: Using DataSource [org.springframework.jdbc.datasource.DriverManagerDataSource@bc5edf] of Hibernate SessionFactory for HibernateTransactionManager
6 juil. 2008 09:34:50 org.springframework.web.context.ContextLoader initWebApplicationContext
INFO: Root WebApplicationContext: initialization completed in 1465 ms
2008-07-06 09:34:50.252::INFO:  Started SelectChannelConnector@0.0.0.0:8080
[INFO] Started Jetty Server
[INFO] Starting scanner at interval of 10 seconds.

Open a web browser and check http://localhost:8080/lombok

Time to add some more difficulties

So far, so good. Now when I tried to import my existing Flex application into this sandbox, I started to encounter some difficulties. I will explain here how I manage to fix them.

First, let’s edit the simple MXML application and add a new Chart component. I let you create a working MXML from Flex Buider. My sample is based on a dataProvider that is an ArrayCollection of values.

...
<mx:LineChart id="linechart1" width="617" height="210" dataProvider="{todoItems}" showDataTips="true">
    <mx:series>
           <mx:LineSeries yField="cpuIdle" form="curve" displayName="Idle"/>
       </mx:series>
   <mx:horizontalAxis>
           <mx:CategoryAxis categoryField="name"/>
   </mx:horizontalAxis>

</mx:LineChart>

Now if you try to compile with mvn install the project you should see this error

...
[ERROR]  Could not resolve <mx:LineChart> to a component implementation.
...
BUILD FAILURE

Add 2 dependencies to your pom.xml

Edit flex_app/pom.xml and add the following dependencies

<dependency>
    <groupId>com.adobe.flex.sdk</groupId>
    <artifactId>datavisualization</artifactId>
    <type>swc</type>
    <scope>merged</scope>
    <version>3.0.0.477</version>
</dependency>
<!-- Add this to avoid the Unable to resolve resource bundle charts for locale en US error //-->
<dependency>
    <groupId>com.adobe.flex.sdk</groupId>
    <artifactId>datavisualization</artifactId>
    <version>3.0.0.477</version>
    <type>resource-bundle</type>
    <classifier>en_US</classifier>
</dependency>

Update also the rvin.mojo plugin version to read (still editing flex_app/pom.xml)

<plugins>
       <plugin>
           <groupId>info.rvin.mojo</groupId>
           <artifactId>flex-compiler-mojo</artifactId>
           <!-- Update here to the correct version -->
           <!-- <version>1.0-beta4</version> -->
           <extensions>true</extensions>

At the end of the file you can also add a new repository (or edit your settings.xml)


<repositories>
     <repository>
         <id>flex-mojos-repository</id>
         <url>http://svn.sonatype.org/flexmojos/repository/</url>
         <releases>
             <enabled>true</enabled>
         </releases>
     </repository>
 </repositories>

Update your local repository

To fix this issue you need to manually import a SWC component and a resource bundle into your local mavené repository. You also need to update the pom.xml so that the flex compiler add at compile time in the external-libs the chart component.

First, I read that you need to import the SWC component that are bundled with Flex Builder. Don’t know exactly why but it doesn’t work if you import datavisualisation component from an external flex SDK 3.0. So here is how to import the Chart component into maven :


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

Then you need to import the resource bundle


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

If you forget to import the resource bundle you’ll see this error message:

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

Rebuild

The application should now build completly with the Chart. It’s really important to specify in the pom.xml a scope of « merged » for the datavisualization plugin as shown below:

<dependency>
<groupid>com.adobe.flex.sdk</groupid>
<artifactid>datavisualization</artifactid>
<type>swc</type>
<scope>merged</scope>
<version>3.0.0.477</version>
</dependency>

If you don’t specify this scope, everything will compile but when you deploy the SWF file on Jetty and press refresh, Flash shows an error message with something like

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

The reason is that the datavisualization needs to be included within the SWF and shall not be loaded as an external library.

I hope that it will help some of you if you play with this nice mojo and with Flex Chart

To conclude a screenshot I took this morning of Chart:

Flex Chart Blazeds

0 no like

Articles similaires:

Default ThumbnailJPA et Maven : gérer 2 persistence.xml distincts Default ThumbnailParis JUG : retour sur la soirée RIA (Adobe Flex et JavaFx) partie 1 Default ThumbnailPoitou-Charentes JUG, première soirée maven le 10 avril Default ThumbnailJPA et tests d’intégrations
  • Kirill Ishanov 26 août 2008 at 18 h 17 min

    What version of maven are you using? I’ve tried both 2.0.8 and 2.0.9 on my Ubuntu Hardy with java 6 and got the following error when pasted content to settings.xml:

    Error reading settings.xml: Unrecognised tag: ‘localrepository’ (position: START_TAG seen \n … @2:20)
    Line: 2
    Column: 20

    The same error appears on other tags

  • Nicolas Martignole 4 septembre 2008 at 14 h 07 min

    Kirill : I had an issue with the Google Syntax color script and the settings.xml was not properly formated. Please try again using the new updated settings.xml file

  • Kjell Arne Brødreskift 11 octobre 2008 at 14 h 13 min

    Looks like a great example project. I get some errors trying to follow your instructions.

    I get this error on mvn idea:idea:
    [INFO] Failed to resolve artifact.
    org.treck:flex_remoted_objects:zip:resources:1.0-SNAPSHOT

    And this on mvn install:
    [INFO] Error executing ant tasks
    Embedded error: taskdef A class needed by class org.xdoclet.ant.XDocletTask cannot be found: org/nanocontainer/ant/PicoContainerTask
    org.nanocontainer.ant.PicoContainerTask

  • Uros 9 novembre 2008 at 20 h 53 min

    Hello,

    Thanks for this article, but I have problem – the same as Kjell Arne.
    The error stack trace is:

    [ERROR] BUILD ERROR
    [INFO] ————————————————————————
    [INFO] An Ant BuildException has occured: taskdef A class needed by class org.xdoclet.ant.XDocletTask cannot be found: org/nanocontainer/ant/PicoContainerTask

    [INFO] ————————————————————————
    [INFO] Trace
    org.apache.maven.lifecycle.LifecycleExecutionException: An Ant BuildException has occured: taskdef A class needed by class org.xdoclet.ant.XDocletTask cannot be
    found: org/nanocontainer/ant/PicoContainerTask
    at ….
    … 29 more

    Can you please add some instruction how to bypass this problem?

    Best regards!

Derniers articles

  • L’instant T où tu poses ta dém…

    Retour d’expérience sur la démission et le moment où vous devez quitter une entreprise.

    6 likes

    24 octobre, 2024
  • The « Robinson » projection – comprendre son système d’information

    Nous sommes en juillet 2022 chez Doctolib. Je travaille sur un projet

    5 likes

    22 octobre, 2024
  • Réussir son démarrage comme Staff/Principal Engineer dans une nouvelle entreprise

    Je prépare une présentation avec mon collègue Théotime pour la conférence Cloud

    3 likes

    6 octobre, 2024

Mots clés

Apple (32) Architecture (14) Big Data (5) Conference (8) Devoxx (55) Dev Web (37) Doctolib (2) geekevent (1) groovy (2) Innoteria (11) Java (517) Linux (10) Non classé (15) Perso (266) Recrutement (2) Scala (30) scrum (43) Société (3) Staff Engineer (5) Startup (21) Web 2.0 (67)

Le Touilleur Express

Blog par Nicolas Martignole

Contactez-moi : nicolas@touilleur-express.fr

Suivez-moi sur X (Twitter) : @nmartignole

Copyright© 2008 - 2024 Nicolas Martignole | Tous droits réservés
  • A propos de l’auteur
  • A propos du Touilleur Express
  • Reset Password

Le Touilleur Express