7.23.2008

Setup Eclipse for Flex and Java Development

With a bit of work it is possible to setup an Eclipse project for Flex and Java development.

1) Check out source into a new Java project
2) Right-click project and add a Flex Project Nature
3) In the project properties dialog select Flex Build Path and set the "Main source folder" to the src directory holding your Flex code
4) Edit the .actionScriptProperties file and set the application path to be the path to your main Flex application MXML file relative to the Flex src directory
5) Configure Java build properties as necessary for the Java code to compile

Configuring BlazeDS

Configuring BlazeDS to access remote Java objects can be a bit of a pain. Here are the steps that are necessary:

1) Deploy flex-tomcat-common to tomcat/common/lib, flex-tomcat-server to tomcat/server/lib.

2) Add MessageBrokerServlet to the web.xml in your web app

3) Deploy some JARs to the WEB-INF/lib directory of your web app: backport-util-concurrent, concurrent, flex-messaging-*

4) Make sure your Java class files are on the web app classpath, typically in WEB-INF/classes

5) Create a services-config.xml
- Declare a service for each Java class that should be accessible
- Declare channels to define how classes may be accessed
- Be sure to set add-no-cache-headers=false on your channel so that IE works properly with HTTPS connections.
- Deploy to WEB-INF/flex within your web app

6) If using tomcat/webapps/ROOT remove context.root from services-config.xml. Otherwise set context-root using mxmlc compile options when compiling the Flex app.

7) To secure the BlazeDS servlet use BlazeDS security constraints but do not restrict the servlet with Tomcat security constraints. It is also possible to use Tomcat security constraints instead of BlazeDS constraints, but the Flex app will not be able to differentiate an authentication failure from a generic channel error.

8) If using multiple web apps with single sign-on the Flex app should be hosted in the same web app that hosts the BlazeDS servlet and Java classes.

9) To see BlazeDS logs use log4j.logger.org.apache.catalina.core=DEBUG