Getting Eclipse set up with Flash+Java+Tomcat, without trouble

We were setting up our development environments recently for a project with an Adobe Flex frontend that pulled data from a Java/Spring/BlazeDS application running on Tomcat. More about setting up that application architecture another time, today I’m going to talk about configuring your Flex project for daily development/debug use.


We were running the application via Eclipse’s “Run on Server” functionality. This works great – it allows us to modify classes or other files in the web app and it will automatically get republished.

I am using the Flex Builder (now Flash Builder 4) plugin for Eclipse to help with coding and debugging. In order to comply with the Same origin policy, the Flex client has to be run in the browser from the same protocol, server, and port as the server it wishes to connect to. So this means the compiled SWF file has to be deployed into the Tomcat instance we just talked about. This property is configured under Project Properties -> Flex Server -> Output folder.

Failed Attempts

We tried a couple different options here.

  1. First we tried placing it directly into the source (WebContent/, or src/main/webapp/) directory of the Java app. This worked when we then started up Tomcat but minor changes to the Flex code did not deploy immediately and we had trouble with caching.
  2. Then we tried setting the Output Folder to the application’s directory underneath Tomcat’s “webapps” directory – the location to which Eclipse publishes. In other words, /Applications/tomcat/wtpwebapps/backend-server/. This worked great until we changed some of the Java code, and Eclipse wiped out the entire output directory when republishing. Then we had to “clean” the Flex project for it to redeploy into that directory. Also, not ideal.
  3. Finally, we tried creating a “dummy” Java web app that would simply act as a holder for the SWF output, and setup the Flex project to deploy into the webapps subdirectory as above. We figured that since we would never be modifying the dummy application, Eclipse would never have to republish. However we were wrong and the next time we changed some Java code everything got wiped out again.

What Works

I finally hit upon an option that would work: proxy Tomcat with Apache 2, and deploy the Flex application directly into Apache’s documents directory. This works because the web browser sees everything as the same server and port, but in reality the Tomcat instance has nothing to do with the deployed Flex code.

Here are the Flex Builder settings I used:

  • Project Properties -> Flex Server
    • Root URL: http://localhost/
    • Context Root: /backend-server/
      • This and the previous setting help tell the compiler what URL the client should use when getting the data from the server.
    • Output folder: /Library/WebServer/Documents/flexclient/
      • (this is the Mac OS X default webserver root)
  • Project Properties -> Run/Debug Settings

This is what I added to my Apache configuration (on Mac OS X, the default location is /etc/apache2/httpd.conf):

<Location /backend-server/>
ProxyPass http://localhost:8080/backend-server/
ProxyPassReverse http://localhost:8080/backend-server/

Restart Apache, and give your Flex client go! You should be all good to go.