Debug Flex & Java Together in Flex Builder 2
I recently conducted an eSeminar on building enterprise applications with Flex Builder and Flex Data Services. You can view the recording of that presentation at: http://seminars.breezecentral.com/p24622178/
In my session I promised that I would formally document the process for debugging Flex & Java together in Flex Builder. So finally, here is that documentation.
If you haven’t already done so, the first thing you will need to do is install Flex Builder 2 as an Eclipse Plugin and Flex Data Services with integrated JRun. You can get these products on the
Adobe website. I use FDS with JRun for this example, but you could easily use Tomcat or any other app server. A few steps may change slightly, but the general concepts would be the same.
Now just follow along.
-
Start Flex Builder & Flex Data Services
-
Create a new Flex Project in Flex Builder
2.1) Specify that the application will use Flex Data Services and that the application should be compiled on the server
2.2) Click Next
2.3) Locate the root folder of your FDS samples application; mine is E:\fds2\jrun4\servers\default\samples
2.4) Change the root URL to be the URL to the samples application; mine is http://localhost:8700/samples/
2.5) Click Next
2.4) Lets name the project crm
2.5) Uncheck the “Use default location” box
2.6) Specify the Folder as <your_fds_samples_application>\dataservice\crm for instance mine is: E:\fds2\jrun4\servers\default\samples\dataservice\crm
2.7) Specify the Main application file as mini.mxml
2.8) Select Finish
- Test everything by right-clicking on the mini.mxml file in the Eclipse Navigator, then Run As -> Flex Application
3.1) Your browser should load the mini application and look like:
- Now back to Flex Builder where we will create another new project, but this time a Java Project
4.1) Name the project samples_server
4.2) Create the project from existing source, specifying the WEB-INF folder of the samples application, in my case: E:\fds2\jrun4\servers\default\samples\WEB-INF
4.3) Select Next
4.4) Go to the Libraries tab and select “Add External JARs”
4.5) Select the jrun.jar file located in <your_fds_install>\jrun4\lib
4.6) Also add the flex-services.jar located in <your_fds_install>\jrun4\servers\lib
4.7) Select Finish
- Setup Java Debugging
5.1) Shutdown Flex Data Services
5.2) In the Eclipse Navigator browse to the src/samples.crm/EmployeeDAO.java class
5.3) Right-click on the EmployeeDAO.java file and select Debug As -> Debug…
5.4) Select Java_Application then New
5.5) Specify the name as “JRun_Debug”
5.6) Check the box “Include libraries when searching for a main class”
5.7) Enter the Main class: jrunx.kernel.JRun
5.8) Select the Arguments tab and enter “-start default” for the program arguments and “-Xms32m -Xmx384m -Dsun.io.useCanonCaches=false” for the VM arguments
5.9) Select the Apply button
5.10) Select the Debug button
5.11) Insure that Flex Data Services started
- Set a breakpoint in EmployeeDAO.java in the findEmployeesByCompany method
- Set a breakpoint in mini.mxml in the fill function
- Right-click on mini.mxml in the Eclipse Navigator and select Debug As -> Flex Application
- You should hit the breakpoint in the mini Flex application, then select Resume in the debugger
- You should hit the breakpoint in the Java backend
- Now jump up and down with joy saying “I can actually debug web applications!”
I hope this is helpful for you. It’s sure helped me figure out just where things in my applications were going wrong.
-James