Flex Builder and Flash Builder both have the ability to setup a few aspects of your BlazeDS project for you. In a previous posting I explained how to set up a BlazeDS project in Flash Builder. When you select “Use remote object access service” you’re telling the IDE to set up a few things for you. Selecting this keeps you from having to import the BlazeDS libraries, add configuration files and set a compiler option that points to the config files.
It sounds nice, but it may not be the best solution. Flash Builder seems to be a bit buggy when you choose this option. As of this posting it seems to incorrectly set the web context for the destination call when making the actual AMF call. More specifically it seems to use the “WebContent” value instead of “WebContext”. The result is that the calls are made to http://localhost:8080/WebContent/messagebroker/amf instead of http://localhost:8080/MyProject/messagebroker/amf. While this may be a bug in the beta version of Flash Builder there are other reasons not to trust this to your IDE.
When you set this up automatically, the config files are put into your WEB-INF/flex directory for you. When you edit these files, Flash Builder prompts you asking you if you really want to do this since they are generated files. Typically you would just hit yes and update the files. Here’s the rub. If you go under the project properties and change the server configuration the IDE may delete those files from the directory. In FlashBuilder if you remove the BlazeDS support after a project has been set up it removes the config files. Why would you do this if you were writing a BlazeDS app? Well maybe someone (me) was trying to fix the destination issue I previously mentioned by changing the WebContext setting. This setting happens to be locked down in an automated setup.
Finally when your application gets all growed up and wants to move out, you’ll probably want to move the build process to a command line utility. At this point you’ll have to know about the libraries, config files and compiler options anyway. So why wait, just set it up on your own to begin with. FlashBuilder isn’t really doing that much anyway.
Set it up yourself
So where to begin. Lets talk briefly about the three main styles of setup that you’ll come across online. First is what we already mentioned, having Flash Builder setup things for you in a combined Flex J2EE project. The second way many sites discuss is creating a project for flex and pointing it to an existing server that’s running BlazeDS. This is a more prevalent option and highlights the separation of concerns that actually exists in any final solution. The third method is to manually create a combined Flex J2EE project. This third option is more ideal for smaller projects.
Lets look at setting up Flash Builder with BlazeDS manually. Go ahead and create a new flash project. Select J2EE for server technology, but DON’T select use remote object access. I have WTP installed so I have Flash Builder create my web app for me by selecting Create combined J2EE/Flex project using WTP.
Finish the set up as usual. Now you’ll need that BlazeDS war everyone talks about. If you don’t have it yet go get it from the Adobe Release Builds page. You can just grab the Binary Distribution. The Turnkey version just includes a lot of stuff we don’t need right now.
Once you get the War we’ll need to import it into
our project. Go to File –> Import then select Archive file under General. Locate the directory where you put the blazeds.war and switch the file type to *.* then select the war.
Now we don’t need everything in this war, sure you can import it all but lets keep things clean.
Deselect the META-INF, classes and src directories. Also you’ll need to change the import into folder field from <project> to <project>/WebContent.
Hit Finish and say yes to overwriting web.xml. See that wasn’t so bad and you just did most of what FlashBuilder did, simply by importing that war yourself.
There is one other thing we need to do before we’re done. The web.xml tells Java where to find the configuration files but we need to let flex know also. It’s pretty easy, just follow my lead.
Open up the project properties and head to flex compiler. See that field additional compiler arguments? We’re going to update it.
We want to add a compiler option pointing to the configuration files. You can use either a path that’s in the classpath or a physical location on your drive. We’ll use the latter. Update the Additional compiler arguments to include the following –services “C:\dev\MyProject\WebContent\WEB-INF\flex\services-config.xml” where dev is your workspace directory and MyProject is your project name.
Hit OK and you’re done.
Setting this up manually is a good practice and will make things easier later when we migrate to Maven and Ant. Stay Tuned!!!!
0 Responses
Stay in touch with the conversation, subscribe to the RSS feed for comments on this post.