BlazeDS, and Java Together – A Simple Tutorial

Steps for Using Flex With Java

1. Note my development system setup. If your system setup is different then you’ll need to adjust these instructions.

a. Windows XP

b. Tomat 6.0 installed in C:\Program Files\Apache Software Foundation\Tomcat 6.0\ referred to as [tomcat-home]

c. Tomat server running on port 8080

d. Flex Builder 3

2. These instructions assume you know how to do the following:

a. Create Java classes

b. Use Flex Builder 3

c. Stop and start Tomcat

3. Download BlazeDS (these instructions are as of June 22, 2008)

a. http://opensource.adobe.com/wiki/display/blazeds/Release+Builds

b. Download the BlazeDS binary distribution

 i. Save the .zip file to your computer

ii. There are two files in the zip – blazeds.war and blazeds-bin-readme.html

iii. Extract blazeds.war to your [tomcat-home]\webapps directory

c. Stop Tomcat if it’s running and then start Tomcat

d. In Windows Explorer navigate to the folder [tomcat-home]\webapps

 i. You should now have a folder named blaseds

ii. Under blazeds is a folder named web-inf

 iii. Under web-inf are several folders, one called classes is where we will put our Java classes so that our Flex application may use them.

iv. Under the folder flex is an xml file named remoting-config where we will put an XML node that tells our Flex application how to connect to the Java class

4. Using a Java IDE (for example Eclipse or Flex Builder 3 with the Java plug-in) create the following Java source file named HelloWorld.java.

package example;

public class HelloWorld {

public HelloWorld() {

}

public String getHelloWorld() {

return “Hello From Java!”;

}

}

Compile the Java source file into a class file (HelloWorld.class). Since our source file specified a package of example, our class file should be under a folder named example.

a. Copy the example folder to [tomcat-home]\webapps\blazeds\WEB-INF\classes

5.  Add the following node to [tomcat-home]\ webapps\blazeds\WEB-INF\flex\remoting-config.xml right after the closing </default-channels> node and before the closing </service> node. Note the values for id attribute and the value for the source tag (the complete path and name of our Java class).

<destination id=”helloworld”>

<properties>

<source>example.HelloWorld</source>

</properties>

<adapter ref=”java-object”/>

</destination>

6. Stop Tomcat if its running and start Tomcat

7. Create a new Flex Project named HelloWorld

a. In the New Flex Project wizard select J2EE as the Application Server type (see the very limited instructions here for some help)

b. Make sure Use remote object access service is checked

c. Click next

d. On the configure J2EE server uncheck use default location for local LiveCyle Data Services server

e. Specify the following values for root folder, root URL, and context root

 i. Root folder: C:\Program Files\Apache Software Foundation\Tomcat 6.0\webapps\blazeds

                                                       ii. Root URL: http://localhost:8080/blazeds

                                                      iii. Context root: /blazeds

f.  Click on the Validate Configuration button – should get the message “The web root folder and root URL are valid.”

g. Click Next and then click Finish

8. In your HelloWorld.mxml create the following source between the <mx:Application> </mx:Application> tags

<mx:Script>

<![CDATA[

import mx.rpc.events.ResultEvent;

import mx.rpc.events.FaultEvent;

import mx.utils.ObjectUtil;

import mx.controls.Alert;

import mx.utils.StringUtil;

private function resultHandler(event:ResultEvent):void

{

//used for debugging - shows details about result

//returned by the Java class method

Alert.show( ObjectUtil.toString(event.result) );

}

private function faultHandler(event:FaultEvent):void

{

Alert.show( ObjectUtil.toString(event.fault) );

}

]]>

</mx:Script>

<mx:RemoteObject id=”ro” destination=”helloworld

source=”example.HelloWorld

result=”resultHandler(event)”

fault=”faultHandler(event)”/>

<mx:Panel x=”10” y=”10” width=”440” height=”200” layout=”vertical” title=”Test Flex 3 Using Java” borderColor=”#008040” fontFamily=”Arial” fontWeight=”bold” fontSize=”13>

<mx:Text text=”Click The Button To Test Getting Data Into Flex From A Java Class” fontWeight=”bold” width=”250/>

<mx:Spacer height=”20/>

<mx:Button label=”Get Hello World!” click=”ro.getHelloWorld()”/>

</mx:Panel>

9. Run the Flex HelloWorld application. You should see an HTML file with a Flex panel and a Get Hello World! button. Click on the button and a Flex Alert component should appear with the words “Hello from Java!”.

10. Note in the mx:RemoteObject tag the value for destination matches the id attribute value and our source matches the value for the source tag in our destination node in the remote-config.xml file.

Trouble-shooting Tips

If you change the HelloWorld Java file then you’ll need to copy the new class file into the [tomcat-home]\webapps\blazeds\WEB-INF\classes folder in the correct package. Then you’ll have to stop and restart Tomcat.

If you change the remote-config.xml file, you’ll need to stop and restart Tomcat. You may also need to rebuild your Flex application before running it again.

Summary:

How easily Flex works with ColdFusion Components (CFCs) is just another reason I miss ColdFusion. But my new company uses Java to develop their web applications and they are not going to change to ColdFusion. But I hope that eventually we will be able to use Flex on the front end and Java on the back end where it makes sense. But first I’ve got to get smart on how to integrate Flex and Java. So I’ve got alot of learning and trial and error. I’ll keep you posted in this series of blog entries.

Up next – sending information from Flex to a Java class.

References

  1. LiveCycle Developer Center
  2. LiveCycle ES vs LiveCycle DS vs BlazeDS – clearing up the confusion
  3. BlazeDS and LCDS Feature difference
  4. BlazeDS Overview
  5. BlazeDS
  6. Creating Flex Builder Projects that Use Server Technologies

 

From Bruce Phillips Blog on Java, ColdFusion, Flex and Spry

About these ads

26 Responses to BlazeDS, and Java Together – A Simple Tutorial

  1. George says:

    Great blog. Nice work.

  2. edpucahh says:

    qf2RvN meqbhkesbmyq, [url=http://krjhtyxbyduq.com/]krjhtyxbyduq[/url], [link=http://fnebrktxgqrr.com/]fnebrktxgqrr[/link], http://qdbdrnpfdomb.com/

  3. yjgaew says:

    MbK0kR nbbuwdfydwfj, [url=http://iafxamxncphd.com/]iafxamxncphd[/url], [link=http://wukazvsezzeq.com/]wukazvsezzeq[/link], http://dcvegpeunwlk.com/

  4. Great site this raajasoft.wordpress.com and I am really pleased to see you have what I am actually looking for here and this this post is exactly what I am interested in. I shall be pleased to become a regular visitor :)

  5. This is quite a hot info. I think I’ll share it on Twitter.

  6. EmpokLamtom says:

    I’m new to this blog. Apologize for asking this though, but to OP…
    Do you know if this can be true;
    http://www.bluestickers.info/ringtones.php ?
    it came off http://ringtonecarrier.com
    Thanks :)

  7. abullyDual says:

    rated site this raajasoft.wordpress.com brill to see you have what I am actually looking for here and this this post is exactly what I am interested in. I shall be pleased to become a regular visitor :)

  8. Mona says:

    Thanks for this article. Could you please suggest me how to develop a Flex application to display charts which projects data from Mysql database using Java as backend?

  9. Constantine says:

    Hi! Thanks a lot for the detailed info, but one silly thing remains unclear for silly me:

    “Compile the Java source file into a class file (HelloWorld.class). Since our source file specified a package of example, our class file should be under a folder named example.”

    How do you do that in eclipse?

    Many thanks!

    • Madalina says:

      In Eclipse after you create a new java project, right click on the name of your project in Package Explorer View and select New -> Package. Give the package the name example and you will see that a new folder appears under src. There you could create a new class HelloWorld and inside it copy the code of the class. You can then press Ctrl+B so that you build all (and thus obtain the .class file). Hope I could help you :)

  10. saliya sajith says:

    hi,
    nice work and thank you a lot. i was searching every where for the REMOTEOBJECT :D

    one issue, if someone is using vista except xp install Tomcat except in program files folder

    thats all thank you again…..

  11. Nasim says:

    Thanks!

  12. Great Article! exactly what I was looking for. Thank you :)

  13. kk says:

    Very helpful artcile..Thank you!

  14. Anirudha says:

    Really helpful for beginners…..
    thanx…..

  15. meenakshi says:

    Hey,Its great for the beginners like me.keep posting such blogs.thanks for help…….

  16. Mona says:

    Hello,
    Just a quick note if you use someone else’s tutorial you should at least quote the name.

  17. Throstur says:

    What would be different with the helloworld.xmlm code when using flex 4 ?
    I can´t run this using flex 4

  18. artis news says:

    artis news…

    [...]BlazeDS, and Java Together – A Simple Tutorial « Raajasoft’s Weblog[...]…

  19. WoW e!Book says:

    WoW e!Book…

    [...]BlazeDS, and Java Together – A Simple Tutorial « Raajasoft’s Weblog[...]…

  20. JavaPins says:

    BlazeDS, and Java Together – A Simple Tutorial « Raajasoft’s Weblog…

    Thank you for submitting this cool story – Trackback from JavaPins…

  21. Download tutorials…

    [...]BlazeDS, and Java Together – A Simple Tutorial « Raajasoft’s Weblog[...]…

  22. Pratibha says:

    Hey i’m not able to see the blazeds file created in tomcat
    Please help

  23. Aw, this was a really good post. Taking a few minutes and
    actual effort to create a great article… but what can I say…
    I procrastinate a lot and never seem to get anything done.

  24. Kaylene says:

    If some one wishes expert view regarding blogging after
    that i propose him/her to go to see this webpage, Keep up
    the good work.

  25. This article provides clear idea in support of the new users
    of blogging, that truly how to do blogging and site-building.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

%d bloggers like this: