Aug 08
Using CFCOMPILE within Eclipse
Posted by James Netherton | Wednesday 08 August 2007 1:11 PM | In ColdFusion
Recently I've been working on a Flex project and have been doing some tinkering with Java. Both languages require you to compile source code in order to execute the target application. After doing some refactoring within the Flex application, it struck me just how much the compiler helps you to scoop up any mistakes that may have been made along the way.
For example, I could change a variable to be of a different class type and the compiler would then list all of the locations where any references to that variable became invalid. It's then just a case of clicking through the errors in the Eclipse problem view and making any appropriate fixes.
I guess this is only helpful for small to medium refactorings. Refactoring on a larger scale you'd ideally want to use a refactoring tool which thankfully Java and Flex 3 have within Eclipse.
It got me thinking though. Seeing as there is no refactoring tool for ColdFusion, would compiling the source code before attempting to run an application, help with fixing bugs and trapping any mistakes that may have been made?
If you don't already know, you can use the cfcompile utility to compile ColdFusion applications into java .class files. If errors are encountered within any source files, they are output in the form of stack traces and in the usual ColdFusion style of "Error x occurred in y file at z location".
I decided to investigate whether I could make use of cfcompile through Eclipse. It's actually quite easy, although not an ideal solution, which I'll elaborate on later.
From the main menu bar choose:
Run :: External Tools :: External Tools
A new window should open listing the external tools that are currently configured in Eclipse. One of the options should be titled 'program'. Right click on the icon and choose 'new'.
Give the configuration a meaningful descriptive name like 'Compile ColdFusion Code'. Then within the 'location' field, enter the full path to the cfcompile .bat or .sh script. For Mac and 'nix users running the ColdFusion J2EE configuration, there's some additional work in order to get CFCOMPILE working. Read all about it here.
Finally click the 'Variables' button. From the list of variables choose ${file_loc}. Click the 'Apply' button and everything should be configured and ready to go!
Select a project or an individual .cfm / .cfc file within your Eclipse resource navigator and from the toolbar area select the 'Run External Tool' icon, which looks like the image below. Then choose the 'Compile ColdFusion Code' option.

If everything works correctly, you should see Eclipse launch the console view. Within the console should be the compilation results. Any errors will appear in red.
As I mentioned earlier, all of this isn't ideal. What would be nicer is if you could click through each error via the 'Problems' view.
What do people think? Would this make your ColdFusion application development and debugging easier in any way?
4 Comments
[Post comment]
1
Posted by dis | Monday 27 August 2007 10:20 AM
- "What do people think? Would this make your ColdFusion application development and debugging easier in any way?"
It shifts some debugging elements from the browser to the IDE... I'm trying to think through how helpfull this would be.... I guess instead of seeing one CFML syntax error for example, you would see a list of all CFML syntax errors? Therefore removing the back and forth time between IDE and browser as you fix one error and return to try again untill you "find" another error.
It makes more sense to have that information availeble in the IDE. I'm certain it would save some time, and though it might not be a huge amount, it certainly feels like a more proactive way to catch those errors.
I might have to give this a go. Cheers for the post on the subject. Were you considering writing something to have the output shown in the problems tab?
2
Posted by James Netherton | Monday 27 August 2007 11:15 AM
Hi,
Yes I did consider looking at writing something to have everything integrated with Eclipse so that it would report problems via the problems view.
Your comment sums up what I was hinting at. I like the compiler to tell me if any problems exist, so that I have a better chance of fixing them in one hit, rather than switching between browser and IDE multiple times.
James
3
Posted by Mike Henke | Monday 17 September 2007 9:50 PM
Is there a way to make this into ant task like jslint or jtidy?
4
Posted by James Netherton | Tuesday 18 September 2007 2:13 AM
Indeed you can create an Ant task for this. Check out this post:
http://www.webdevref.com/blog/index.cfm?t=Use_ecli...