Just Blaze… getting started with Blaze DS

Blaze Data ServicesIn December 2007 Adobe released part of their Live Cycle (LC) suite as Open Source on Adobe Labs and named it Blaze DS. Having used LCDS for some time I was interested in seeing how the Open Source version was compared to the expensive LCDS suite. The result of this investigation is this write up on how to get started with BlazeDS.

Demo application

In addition to this written stuff I have created a pretty simple demo application which can help you getting started with Blaze DS. It is just a simple app for collecting notes and links, nothing very fancy or interesting but this is just a simple application for showing how easy it is to get started with BlazeDS. The sample application contains a Flex 3 Web- and Air Application and a Java Web Application.

It’s really simple to get this sample running all you need is to extract the files and execute two simple commands. Make sure you have installed the following on your computer:

Once you have those two things in place you can follow these simple steps to view the application:

  1. Download the demo application source code: blaze-poc-v3
  2. Extract the ZIP file to any directory
  3. Open the file deploy/blazeds-poc.properties and edit the property echo.db.path to reflect the location where you extracted the source code.
  4. Run the command: install-flex-libs
    This command installs the BlazeDS JAR’s in your local repository.
  5. Run the command: mvn install
  6. Navigate to the directory blaze-poc-web and run the command: mvn jetty:run
  7. Open the URL: http://localhost:8081/blaze-poc-web/

Now that you have seen the sample application you are probably interested in seeing how BlazeDS is setup. Continue reading and I will go through some of the basic steps. In order to build Flex applications easily you should use Flex Builder 3 as it give you numerous benefits and helps you develop much more rapidly than any other Flex authoring tool.

Configuring BlazeDS in you Java Web Application

Create a Java web application in Eclipse (you might want to use MyEclipse or something similar to make web development even easier in Eclipse). Grab the latest distribution from Adobe Labs and unzip the content to a folder somewhere on your machine. Unzip the file blazeds.war into the root directory of your web application. You should have a folder structure like this:

WEB-INF\flex
WEB-INF\lib
meta-inf

Delete all the JAR-files in the WEB-INF/lib directory, we’re going to let Maven handle the dependencies for us instead of having to do this ourselves. Adobe seems to be stuck in the previous century when it comes to Java development and have not published BlazeDS artifacts to any Maven repository. Luckily the guys and girls developing the Open Source Igenko CMS has put up BlazeDS artifacts in a repository which we can use. BlazeDS dependencies are configured as described in the write up from Igenko.
Upate: There is still no sign of the Blaze DS JAR’s getting put into a public Maven repository and they are now a part of the demo application (thanks Per-Otto!), see a more detailed description of why at the end of this post.

Spring and BlazeDS

In order to enable BlazeDS to utilize the power of Spring you can do this by creating a SpringFactory class. Christophe Coenrates describes the required steps in the article “Using Flex and Spring” on Adobe Developer Center. In the enclosed sample project a SpringFactory class is configured in the configuration file WEB-INF/flex/services-config.xml

<factories>
  <factory id="spring"
      class="com.moneytalks.blaze.poc.SpringFactory"/>
</factories>

Using Remote Object in Flex

Adobe usually says that you should add the -services compiler argument telling the MXML compiler where the Flex configuration is located. This is IMHO not a very smart way of doing this at it forces you to have the exact same file path in all environments you deploy you application.

Instead of passing in the path for the Flex configuration a better option is to pass information required by RPC- and Messaging Services either with Flash Vars which makes it easy to adjust endpoint servernames, file paths, etc in different environments. This approach was first brought to my attention by Mike Nimer in his blog post Bye bye -services. I recommend following this approach as it makes it easy to deploy your application anywhere without having to recompile your application

Start developing!

That is pretty much all the important thins you need to know before you can start enjoying rapid development using BlazeDS. You will hopefully experience the joy of being able to focus on developing a great application instead of spending time writing boiler plate code moving data between client and server.

In order to get a better overview of the messaging features you can check out some of the great samples provided by Christophe Coenraets.

This article is also available in Norwegian.

Note!

Since I wrote this article it seems as if the artifacts on the Maven repository I used for the demo applciation have become unuseable. Attached to the article is an updated archive which have the BlazeDS JAR-files enclosed (in the directory called /flex-libs) and with a script (install-flex-libs.sh/.cmd) which installs them in your local repository.

Thanks to Per-Otto for updating the demo project and sending me the update!

Note 2!

There is a bug in the POM of the web application, substitute the webApp configuration with the following lines (I will update the sample projcet, but this is a temporary solution):

<webAppSourceDirectory>${basedir}/target/${project.artifactId}-${project.version}</webAppSourceDirectory>
<webXml>${basedir}/target/${project.artifactId}-${project.version}/WEB-INF/web.xml</webXml>
<classesDirectory>${basedir}/target/classes</classesDirectory>

February 22nd, 2008 | Flex, work

12 comments

There was an typing error in Note 2 which I have corrected, sorry about that..
The sample should work just fine if you add this to your POM

Comment by leftieFriele — November 14, 2008 @ 10:01 am

For Step3 I took the file blace-poc-web/deploy/blazeds-poc.properties

Somewhere between step 2 and 5 everybody who gets the error “[ERROR] BUILD ERROR
[INFO] ————————————————————————
[INFO] c:\dev\applications\Adobe\Flex Builder 3\sdks\3.0.0 does not exist. flex.home property must be set.”
needs to change somthing more:
PATH_TO_YOUR_FLEX_SDK_VERSION
in “UNZIPDIR/blaze-poc-flex/profiles.xml”.
Setting PATH_TO_YOUR_FLEX_SDK_VERSION to ${env.FLEX_HOME} and setting this variable in my environment variables in the user variables to the right path did let me finish step 5 (don’t forget to restart the “cmd” if ur os has “Win” in its name, for the new set/created variables to be accessable). So finally after about total 45′ from step 1 to step 6 finally it told me Jetty was started. (Maybe its just me, maybe its because this is the first time I use maven an it downloaded a LOT of things ;) .)
But this is bad: by clicking on the link in step 7 I get a “jetty-powered”
‘ERROR 503

SERVICE_UNAVAILABLE

RequestURI=/blaze-poc-web/’
maybe caused by those to Warning while executing step 6 (outcome in this order):
2008-11-13 21:12:38.877:/blaze-poc-web:INFO: Initializing Spring root WebApplicationContext
log4j:WARN No appenders could be found for logger (org.springframework.web.context.ContextLoader).
log4j:WARN Please initialize the log4j system properly.
2008-11-13 21:12:38.095::WARN: Failed startup of context org.mortbay.jetty.plugin.Jetty6PluginWebAppContext@1e22632{/blaze-poc-web,D:\tmp\_developtes
t\blaze-poc-v3\blaze-poc-web\src\main\webapp}
org.springframework.beans.factory.BeanDefinitionStoreException: IOException parsing XML document from ServletContext resource [/WEB-INF/classes/applic
ationcontext.xml]; nested exception is java.io.FileNotFoundException: Could not open ServletContext resource [/WEB-INF/classes/applicationcontext.xml]
[...a lot of stack...]
2008-11-13 21:12:38.095::WARN: Nested in org.springframework.beans.factory.BeanDefinitionStoreException: IOException parsing XML document from Servle
tContext resource [/WEB-INF/classes/applicationcontext.xml]; nested exception is java.io.FileNotFoundException: Could not open ServletContext resource
[/WEB-INF/classes/applicationcontext.xml]:
java.io.FileNotFoundException: Could not open ServletContext resource [/WEB-INF/classes/applicationcontext.xml]
[...a lot of stack again...]
2008-11-13 21:12:38.283::INFO: Started SelectChannelConnector@0.0.0.0:8081
[INFO] Started Jetty Server.

Has anybody any idea what went wrong? (I tryed both replacing and inserting the code from “Note2!” in the named file. replacing told methis at step 6:
‘[ERROR] BUILD ERROR
[INFO] ————————————————————————
[INFO] Webapp source directory D:\tmp\_developtest\blaze-poc-v3\blaze-poc-web\target\blaze-poc-web-${project.version does not exist’
)

Sorry for this big comment, I couldn’t find a mailcontoct at this site.

Greetings from Germany,
Karfau

Comment by Karfau — November 13, 2008 @ 10:36 pm

[...] Dalløkken :: Just Blaze… getting started with Blaze DS :: Covers using Maven with a BlazeDS project, includes a sample [...]

Pingback by BlazeDS « Flex Generation Weblog — October 14, 2008 @ 10:20 am

[...] Dalløkken :: Just Blaze… getting started with Blaze DS :: Covers using Maven with a BlazeDS project, includes a sample [...]

Pingback by Blazeds « It’s all about RIA — October 14, 2008 @ 7:27 am

i am gonna show this to my friend, bro

Comment by NipNeisapafseS — October 6, 2008 @ 3:43 am

This was just a number I chose for the Flex JARs since there is no offical Maven repository with the Flex JARs. But, rumors has it that we might expect something from Adobe when it comes to Maven support.

Comment by leftieFriele — July 28, 2008 @ 8:07 am

how did you determine the version of the flex JAR’s?

Comment by codecraig — July 25, 2008 @ 6:56 pm

[...] er også tilgjengelig på engelsk og i tillegg publisert hos [...]

Pingback by Tjuvstart din utvikling med BlazeDS : her er mitt arbeid — June 24, 2008 @ 8:28 am

I just noticed that the Maven repository I used for the BlazeDS artifacts has an invalid version of the Messaging components… unfortunately Adobe does not like Maven (or care about the fact that the entire globe use it) so they refuse to make them available…
however you can vote for the bug here: http://bugs.adobe.com/jira/browse/BLZ-71

and you’ll also find some links to people who have put the artifacts out on the Maven repositories.

Comment by leftieFriele — June 12, 2008 @ 2:23 pm

@mm just remove the import statement in the echo.mxml file. I forgot to remove it, sorry. I have updated the ZIP with this change.

I also detected an error in the Israfil maven plugin for building the Flex application. It has a dependency for the maven-dependency-plugin version 2.0-alpha4 which no longer exists. To fix it change it to 2.0 in the file net/israfil/mojo/maven-flex2-plugin/1.3/maven-flex2-plugin-1.3.pom in you local Maven repository.

Comment by leftieFriele — May 18, 2008 @ 5:29 pm

Using Flex sdk_3.0.0.477
mvn install fails with
Error: Definition com.moneytalks.blazepoc.utils:MessagingHelper could not be found

Comment by mm — May 16, 2008 @ 6:14 pm

Thanks a lot! We are using Blaze DS without Flex (just Flash and AS3) so I had to downgrade your sample app a little. But still, it was a very good starting point to get into Blaze DS using Spring and Maven.

Comment by Jakob Sommerhuber — March 4, 2008 @ 4:45 am