May 6 2008

Groovy + ColdFusion = Happy

Posted by Joe Rinehart at 10:46 AM
10 comments
- Categories: Joe Drinks Java

Over the past month or so, I've become less and less enchanted with using ColdFusion Components to model my applications. They're verbose, and they don't support many constructs I've gotten used to in Actionscript 3.

I've started looking at Groovy, a dynamic language that compiles to the JVM, as an alternative. In theory, results in true Java classes that ColdFusion can use like any other Java class, but is also a truly dynamic language.

I was pleased to find that it simply works: creating a Java project in Eclipse, adding a Groovy class to it, and exporting a .jar into WEB-INF/lib makes the compiled Java version of the Groovy class available upon restarting ColdFusion, just like writing Java. Woot!

Here's the thing, though: you still have this code -> compile -> restart ColdFusion bit to deal with.

I've almost fixed that - I've got a GroovyLoader CFC here that wraps GroovyClassLoader, allowing dynamic compilation of Groovy classes into a running instance of ColdFusion. I'm going to clean it up and test it some on my flight (boarding now!), and hopefully post it later this week...

Comments

Allen

Allen wrote on 05/06/08 11:19 AM

Nice. I've peaked at Groovy and Grails a bit recently, too.

So what exactly is accomplished by this? Essentially a nicer way of writing CFCs? Why keep using the ColdFusion at all? Works as a better glue on the front end?
Dan Roberts

Dan Roberts wrote on 05/06/08 11:33 AM

The sounds great. Do you know if other languages that can be run-on/compiled-to Java (JRuby, JPython, etc) could be used in this manner or is Groovy special in this regard?

What are your thoughts on this versus the possible availability of a full CFScript or AS support in CF9?
Richard Davies

Richard Davies wrote on 05/06/08 1:24 PM

Sounds interesting. For me personally, I think the hassle of the code -> compile -> restart CF workflow would negate any benefits gained by using something else like Groovy. But if you could eliminate that with your GroovyLoader CFC then it would make it *much* more enticing.

I'm looking forward to taking a look at it! (I've never used Groovy before, but have heard some good things about it.)
Asif Rashid

Asif Rashid wrote on 05/06/08 3:22 PM

WOW. That is really cool. Waiting for your GroovyLoader CFC. By adding grail or GORM we get better business.
Joe Rinehart

Joe Rinehart wrote on 05/07/08 7:36 AM

@Allen - I agree with you - I'm not sure how valuable the accomplishment is yet, but it was a fun thing to cobble together. I still can't find anything on the HTML end (Grails included) that I like as much as what the ColdFusion product has to offer.

@Dan - Haven't explored other languages, but whatever I release will be open enough to try to adapt. It's not terribly complicated...basically wraps GroovyClassLoader to build URLs to load into its classpath, then compiles any .groovy files found in those directories.

@Asif - GORM is giving me fits. I've bootstrapped a DefaultGrailsApplication instance, based on the code on the standalone GORM site, but while I get the version and Id properties added to the class the dynamic persistence methods aren't working yet. If I get that working, you can bet I'll blog it :).

-----

Outside of Grails, there are folks who have hooked up Groovy classes to Hibernate via JPA annotations, which is another thing I'll be exploring. Not something that I think everyone in the CF community would adopt, as it requires moving off of JRun and treating CF as a foundation for a JEE application rather than a server on which to develop multiple applications
Indy Nagpal

Indy Nagpal wrote on 05/11/08 8:09 PM

Hi Jo

Looking forward to the GroovyLoader code.

It would be nice to be able to load the classes dynamically.

Indy
Andy Powell

Andy Powell wrote on 05/12/08 8:20 AM

@Joe good to see you've taken things to heart. The key here is truly getting people to look at ColdFusing (the server) as just another J2EE app to leverage in your application. Once you get past that mindblock, we're going to open a lot of eyes.

@Allen - you hit the nail on the head. It is EXCELLENT as a glue to bring data to the UI be it CF rendered HTML or XML for AJAX, or data to Flex via AMF.

@Richard - on my laptop it takes less than 20 seconds to restart ColdFusion, running in JBoss. I don't buy your argument, sorry.
Laura

Laura wrote on 05/13/08 5:29 PM

Hi Joe,
I'd love to see a more complete example of how you tie all the parts together, and a bit more about your setup.
Thanks!
Richard Davies

Richard Davies wrote on 05/21/08 7:22 PM

@Andy Powell - I'm glad you like restarting CF on your laptop. Again, for me personally, having to restart CF after *every* code change would be very arduous. Not to mention that since we're currently using a shared development server (no need to point out the issues with that--that's just the way we do it for now) this would probably drive the other developers crazy too.
Chris Phillips

Chris Phillips wrote on 07/24/08 6:39 PM

Joe,

You should probably take a look at what Barney Boisvert has been doing. I think he has the class loader done and other cool stuff. Take a look here. http://www.barneyb.com/barneyblog/projects/cf-groovy/

Write your comment



(it will not be displayed)