Working with Eclipse is a great experience with lots of powerful features at your fingertips. Unfortunately, for a beginner it can be a little difficult to get used to and not immediately obvious how to do certain tasks. Setting up projects can be particularly challenging, especially if you have a lot of extra development requirements (for example, using Maven, Ant, Sping, etc.). Using the standard Adobe getting started guide gives you a gentle introduction to remotiing and messaging, but doesn’t give you details on how to set up a clean “bare bones” application.
This article lists the steps to create a bare bones BlazeDS server configuration using the turnkey solution.
What You’ll Need
First I’ll assume you have already downloaded and installed the following:
- Eclipse
- Flex Builder (or Flex Builder plugin for Eclipse)
- BlazeDS turnkey
If you followed all of the instructions for installing and running the basic BlazeDS turnkey, then you currently have a tomcat server running a demo on localhost (port 8400). If successful, you should see the BlazeDS index page by clicking here. If you see an error at this point, then you can go and check your server logs and try to correct it. Do not proceed with this guide until you see the functioning index page.
Now you have successfully installed Tomcat and BlazeDS turnkey, you will need to turn it off as you won’t be using it from here. Yes that’s right, turn it off! Shutdown the tomcat server using any method you choose (i.e. ctrl-c, shutdown.bat, stop the service, catalina stop, etc.). This will free up port 8400 and allow you to run the server from Eclipse after we have configured it.
Setting up Tomcat in Eclipse
These are the steps for creating a connection to the tomcat server:
- Start Eclipse and select the “Java EE” perspective
- In the bottom panel, select the “Servers” tab
- Right click on the panel and select “New->Server”
- Select the server settings and point them to your newly installed tomcat server. The installation directory should be “<base turnkey installation dir>\tomcat” (in my case this is “C:\blazeds\tomcat”).
- Click Finish
Once you have completed these steps, you should see a new server created in the “Servers” panel, plus a new tree entry in the Project Explorer (also called “Servers”). Your environment should look a bit like this.
Creating a Project
The next step is to create the server side project.
- Create a new “Dynamic Web Project” with the following settings:
- Project name: myBlazeProject
- Target Runtime: “Apache Tomcat x.x” (this is the server you created in the last section)
- Configuration: Default Configuration for Apache Tomcat x.x
- Click “Finish”
After creating the project, your environment should look a little like this.
Creating the Bare Bones BlazeDS Configuration
Ok, we now have the server set up and a basic project. The next steps set up the BlazeDS libraries and configure the environment to auto-update the server when the project is built.
- Overwrite the contents of your “WebContent” directory with the BlazeDS directory structure “<base turnkey installation dir>\tomcat\webapps\blazeds”. The result should look a little like this.
- Right click on your newly created “myBlazeProject” project and select “Properties”
- Select “Java Build Path” from the list in the left hand panel.
- Set the “Default output folder” to “myBlazeProject/WebContent/WEB-INF/classes”. This will cause your web server to automatically update every time you rebuild your project.
Create a Basic Remote Class
Great! We’re nearly there… now let’s create and configure a Java class so we can test our configuration.
- In the “myBlazeProject/WebContent/WEB-INF/src” directory, create a new class called HelloWorld.java.
- Configure BlazeDS to allow remoting requests to the HelloWorld class by adding a destination to the “remoting-config.xml” file found in the “myBlazeProject/WebContent/WEB-INF/flex” directory. Use the following destination configuration:
- Start your application server by clicking on the green “play” button. Verify your web application is configured by going to the following URL (The url and port may vary depending on your application server configuration and what you named your project): http://localhost:8400/myBlazeProject/
If your server is not configured to display directory contents, you might see a 404 error. This is OK, but failure to connect errors are not.
public class HelloWorld {
public String sayHello(String name) {
return "Hello, " + name;
}
}
<destination id="HelloWorld">
<properties>
<source>HelloWorld</source>
</properties>
</destination>
Create a Flex Project
Whether you use the Flex Builder 3 plugin for Eclipse or standalone Flex builder 3 installation is entirely up to you. It’s possible to manage your Flex and Java code in one IDE if you use the plugin, but you may prefer the standalone IDE instead.
These steps create the Flex project and link it to your server:
- Create a new Flex Project
- Project name: testHelloWorld
- Application server type: J2EE
- Use remote object access service: enabled (with “LiveCycle Data Services” selected)
- Click “Next >”
- Use these settings:
- Root folder: point this to your “WebContent” directory in the Java project
- Root URL: http://localhost:8400/myBlazeProject/
- Context Root: /myBlazeProject
- Click “Validate Configuration”
- Click “Finish”
Create a Client Test Application
Finally, let’s update the Flex project to use our BlazeDS Server so we can test our remote object:
- Update the testHelloWorld.mxml file with the following code:
- Build and Run!
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml">
<mx:RemoteObject id="ro" destination="HelloWorld"/>
<mx:TextInput id="n" change="ro.sayHello(n.text)"/>
<mx:Label text="{ro.sayHello.lastResult}"/>
</mx:Application>
If all went well, then you should have a working Flex app that connects to your remote service and responds with “Hello, <your name>”. Something like this.
Troubleshooting
If you for some reason your components don’t talk to each other after following all the steps, try cleaning the projects and restarting the server.
Server Side Debugging
Now that we have created the bare bones server in this manner, we can use the fantastic debug functionality provided by Eclipse in the Java server code as well as the Eclipse client code!
To use the Java debug mode, just add your breakpoints to your source files and make sure the server is running in debug mode. Then when your Flex apps call the remote objects, they will trigger the debug mode and Eclipse will automagically put you into Java debug mode.
Further Reading
This article was inspired by the excellent in depth articles provided by the following sources:
- Bare Bones BlazeDS Object Remoting – by Dustin Marx
- Building Web and Desktop Applications with BlazeDS and AMF – by James Ward and Shashank Tiwari
Perfect article! You are great! Thank you very much. You had saved many hours of environment setup
You’re very welcome Winston. Thanks for the feedback.
Nice article and very helpful. Validate Configuration kept failing for me, until I relalized that I needed to go back and add the myBlazeDSProject to to the Server under add and remove. Also the placement of the src/java didn’t allow me to debug and see the java src. Didn’t get to the bottom of this, so I ended up using WTP. Thank for posting.
This can be a pretty temperamental environment to set up. As mentioned in the troubleshooting section, cleaning the project (from the menu “Project->Clean..”) can help to alleviate problems as well as restarting the server/Eclipse and sometimes the server hardware itself. This method really works so it is worth retracing your steps.
Incidentally, the “validate” button in FlexBuilder can also be inconsistent. I have found that the client and server will still communicate correctly even if the validation failed.
Once set up, it all works very nicely and I have had few problems with it.
Help! I’ve done everything through “Create a Flex Project”, but when I try to validate the new Flex project configuration, it gives me an error “Cannot access the web server. The server may not be running, or the web root folder or root URL may be invalid.”
When I validated the server was running after setting up the BlazeDs Turnkey, I saw the BlazeDS page. Now when I bring up http://localhost:8400 I get:
Directory Listing for /
Apache Tomcat/6.0.14
My eclipse project is named ReportGenTool and I’ve overwritten the WebContent directory with the META-INF and WEB-INF directories from the BlazeDS installation (C:\blazeds\tomcat\webapps\blazeds). According to Eclipse the server is running.
My Flex project is named ReportGenTool and is located in another directory away from the Eclipse project directory. My root folder is: C:\Projects\workspace\ReportGenTool\WebContent
Root URL: is http://localhost:8400/ReportGenTool/
Context root is: /ReportGenTool/
Any idea what might be wrong? What didn’t I configure that needs to be configured?
Thanks in advance.
OK, the validate button doesn’t always work when setting up the project, particularly if you are using the Flex plugin to Eclipse instead of separate FlexBuilder and Eclipse. Getting a 404 error is ok too as you’re not creating a web page here, you’re creating an endpoint. As long as you can continue with creating the project carry on and finish the setup.
Go through and finish creating the Hello World client/server and config. You will likely find that it will work for you.
As mentioned in the troubleshooting section: if you have problems, make sure you clean your projects and confirm that your current Project is running on the server (see DaddyDogs comment above).
Thank you!
Every step worked exactly as advertised!
I have been struggling for a few days now trying to put all the blazeds bits and pieces together using docs and tutorials.
I was able to configure and run application in eclipse. Now in order to deploy as a war file in tomcat or any other app server what is involved. Has any one tried deploying war to app server from eclipse. I tried creating war and deployed that to tomcat. UI shows up but does not fetch any data from the server. Any pointers would be of good help for deployment as war in app server.
Thanks a lot for this article! I had some problems finding a working setup, since I am quite new to application server issues in Java. Especially the integration with Eclipse enables an efficient workflow…
This is exactly the kind of tutorial I was vainly searching for on Adobe’s BlazeDS pages. It is very much appreciated!
Hi,
Good tutorial, of only I’d found it earlier.
I already have my web app going on localhost using blazeds remoting, to provide access to my hsqldb database.
I now have the challenge of deploying it on an existing tomcat server. However when i combine the blazeds.war with my app, package it up, and deploy it, i cant get access my data.
Do you know how to get BlazeDS working, not on the tomcat instance that the turnkey dist comes with.
Regards,
Tom
Nice Post ,thanks ,But I wonder if this is the best way to integrate blazdeds and jee in eclipse ,can I just click run on server ,and eclipse automatically start tomcat and deploy the applicatin ? Because flex builder does has a run as server choice.
Tom,
You should be able to get BlazeDS working by copying the correct files into your structure. Please re-read the section that starts:
Overwrite the contents of your “WebContent” directory with the BlazeDS directory structure “ \tomcat\webapps\blazeds
Tony,
Yes, you can configure ant scripts to perform more complex “Run” operations.
I followed this carefully (twice), and bombed out on the Flex part. The server validation failed and then my AIR app threw an exception about “Send failed” and my Flex app also couldn’t find what it was looking for. I cleaned projects etc.
I’m using FB 4 beta, but the steps are the same (except a BlazeDS option is available in project creation and you need to wrap the RO in ).
Here are some questions:
1) I assume that after running the myBlazeProject, I shouldn’t stop it before running the testHelloWorld project. Correct?
2) I don’t understand how publishing the java into the local project file structure ties it into Tomcat. Shouldn’t we be publishing into the /blazeds/Tomcat directory structure somewhere? Or does Eclipse do some magic to tell Tomcat where to find requests to our project?
TIA for any help.
In the “myBlazeProject/WebContent/WEB-INF/src” directory, create a new class called HelloWorld.java.
then it doesn’t work for me
It works when I leave the file in
“myBlazeProject/Java resourcers: src” folder
Hi,
I am using LiveCycle Data Services ES 2.6.1
I’m very tired with error:
[RPC Fault faultString="Send failed" faultCode="Client.Error.MessageSend" faultDetail="Channel.Connect.Failed error NetConnection.Call.Failed: HTTP: Status 404: url: 'http://localhost:8400/TestApp/messagebroker/amf'"]
at mx.rpc::AbstractInvoker/http://www.adobe.com/2006/flex/mx/internal::faultHandler()[C:\autobuild\3.2.0\frameworks\projects\rpc\src\mx\rpc\AbstractInvoker.as:220]
at mx.rpc::Responder/fault()[C:\autobuild\3.2.0\frameworks\projects\rpc\src\mx\rpc\Responder.as:53]
at mx.rpc::AsyncRequest/fault()[C:\autobuild\3.2.0\frameworks\projects\rpc\src\mx\rpc\AsyncRequest.as:103]
at mx.messaging::ChannelSet/faultPendingSends()[C:\autobuild\3.2.0\frameworks\projects\rpc\src\mx\messaging\ChannelSet.as:1482]
at mx.messaging::ChannelSet/channelFaultHandler()[C:\autobuild\3.2.0\frameworks\projects\rpc\src\mx\messaging\ChannelSet.as:975]
at flash.events::EventDispatcher/dispatchEventFunction()
at flash.events::EventDispatcher/dispatchEvent()
at mx.messaging::Channel/connectFailed()[C:\autobuild\3.2.0\frameworks\projects\rpc\src\mx\messaging\Channel.as:997]
at mx.messaging.channels::PollingChannel/connectFailed()[C:\autobuild\3.2.0\frameworks\projects\rpc\src\mx\messaging\channels\PollingChannel.as:354]
at mx.messaging.channels::AMFChannel/statusHandler()[C:\autobuild\3.2.0\frameworks\projects\rpc\src\mx\messaging\channels\AMFChannel.as:390]
Help me, please!
Thanks a lot!
Just one thing, I’d like to add here.
You create a remote object with an id and a destination. I must say, I’m quite new in working with flex and blaze. But I am quite sure that the endpoint location is missing on flex side.
So you should add “endpoint=”http://localhost:8080/yourproject/messagebroker/amf”, to let the client now, where his endpoint is located.
If I’m misunderstanding something, feel free to correct me. But thats one thing i was missing in most tutorials. After I added that to my definition of the remote object, it all worked fine.
regards, Joey
PS: this relates to the error message: “MessagingError message=’Destination ‘helloworld’ either does not exist or the destination
has no channels defined (and the application does not define any default channels.”
Joey. The default endpoint for remote objects is specified in the remoting-config.xml file; a link to this file (via the services-config.xml) should be included in the flex projects compiler arguments if you setup the flex project correctly.
i just want to know which is better, work eclipse and flex builder plugin together or separate.
anothe thing , i follow the tutorial and in flex builder there is the field Output folder with pointo to C:\wsflex\myBlazeProject\WebContent\testHelloWorld-debug, its ok at first but when i change something in flex builder the changes doesn’t appear, in flex builder there is a bin-debug folder in the project i think this is linked with C:\wsflex\myBlazeProject\WebContent\testHelloWorld-debug, but the changes doesn’t appear, why?
[...] Server and Client applications as described here. Setup data source in Tomcat as described here. But, instead of putting myapp.xml under [lcds [...]
This code did not work to me.
I dont know why, but the flex project not works in java project.
You said:
Root folder: point this to your “WebContent” directory in the Java project
Is that a physical path?
Root URL: http://localhost:8400/myBlazeProject/
Context Root: /myBlazeProject
I use a standalone flex with eclipse, so, I developed the application using:
1. Flex Project
2. I used blazeDs WAR file
I dont know why but I’m always have a problem with a deploy.
So, now works with this option but I will try use your configuration again.
Congratulations.
Best regards.
Thanks for this great tutorial !
Helped me a lot getting ready to develop server-side code. Eclipse amazes me more and more every day :p
Keep up the good work, cheers !
[...] http://flexbandit.com/archives/55 [...]