Blog

ColdBox Presents: Groovy Integration

Luis Majano April 15, 2009

Spread the word

Luis Majano

April 15, 2009

Spread the word


Share your thoughts

We are releasing a 1.0 version of our GroovyLoader plugin for ColdBox Applications today.  This plugin can be found in the extra downloads section of the ColdBox Website as part of the projects pack.  So what did we do, well, based on Barney Boisvert's inspiration on CFGroovy, we decided to create a plugin that would leverage ColdBox users with the Groovy Scripting Language.  We took some different approaches to the integration and we still have many things planned for it.  But as of now, these are the features that our GroovyLoader exhibits
  • Drop and Play functionality on ANY ColdBox application running on Railo 3.0 >, Adobe CF 8 >, or Open BD
  • Load a groovy environment (1.6.0) into any ColdBox application without modifying the running CF engine.  It uses our integrated JavaLoader to load all necessary libraries without modifying the CF engine.  It can also, load up ANY library you place in the GroovyLoader's lib directory automatically.  So if you kids start fooling around with packaged groovy libraries or java libraries like Hibernate, Spring, Gorm, etc. You can do so, by just dropping the files in that pre-configured folder.
  • Setup of a directory that will hold groovy classes/scripts, that the GroovyLoader will try to load at runtime. Uses the configureClassPath() method of the plugin and usually called once.
  • Integration with the ColdBox cache to provide resolution of parsed groovy-to-java classes for all parsed groovy source, including custom groovy source compilations
  • Ability to clean the parsed class cache from the ColdBox cache
  • Ability to clean the groovy classloader cache of parsed bits
  • Ability to handle complex groovy/java relationships and hierarchies
  • Easily extend/decorate the plugin to meet your needs or enhance it
  • Create groovy classes: create(clazz)
  • Execute groovy scripts: runScript(scriptName,varCollection)
  • Execute groovy source code: runSource(scriptSource,varCollection)
  • Execute groovy source code using a custom tag import
  • Groovy scripts and source code executions will be binded with the following variables. This means that the groovy scripts that are executed using runScript() and runSource() will have the following variables IMPLICITLY created at runtime. This creates a data bridge between ColdFusion and Groovy.
    • A custom passed structure called varCollection. This can have anything you like.
    • The coldbox request collection: coldbox_rc
    • The following coldfusion variables:
      • cf_pagecontext : The coldfusion pagecontext object
      • cf_application : The coldfusion application scope
      • cf_server : The coldfusion server scope
      • cf_session : The coldfusion session scope (if available)
So how does it work. Well, first of all, the download includes a very simple application that you can replicate and learn from.  As our integration progresses we will be adding more functionality and some extra surprises our very own Sana Ullah has been working on for quite a while now. Step1: Install the custom plugin in your application or as a core plugin, basically drop the GroovyLoader folder in your plugins directory of your app Step 2: Init the plugin on application start, usually the application start handler: Step 3: That's it, you can now use it a la carte to create groovy classes, run scripts, or run on deman source code via the method or the imported tag. You can see some sample handler methods below: var rc = event.getCollection(); rc.oHello = instance.GroovyLoader.create("Hello"); event.setView("home"); var rc = event.getCollection(); instance.GroovyLoader.clearClazzCache(); setNextEvent('groovy'); rc.varCollection = {createdAt=now()}; instance.GroovyLoader.runScript('Test',rc.varCollection); event.setView("runscript"); var rc = event.getCollection(); /* Source */ var source = "varCollection.GroovyArray = [1,2,3,4]"; rc.varCollection = {createdAt=now()}; instance.GroovyLoader.runSource(source,rc.varCollection); event.setView("runSource"); def today = coldbox_rc["today"] def SubjectLine = ["Hello","my","name","is","Luis Majano.","Expressed at",today] //Place in ColdBox event context coldbox_rc["SubjectLine"] = SubjectLine.join("_") I hope you enjoy this plugin and you help make it even better and better.

Add Your Comment

(3)

Apr 16, 2009 16:37:35 UTC

by Manithan

That is really great which is the perfect timing i was just looking for it where i have dynamic bean created and was planing to use with spring. i am really excited to try this one. thanks a lot. you rock!!!

Apr 22, 2009 04:45:05 UTC

by Martin

WOW - thats is what i need - thanks a lot! But the only question for me is: How can i use the hibernate plugin? In the CFGroovy project from Barny there is hibernate integrated. Is there a way to integrate it easy in the Coldbox-Groovy Plugin? My idea is to make the whole DAO-Layer in groovy+hibernate. and call it from CFCs :-)

Apr 22, 2009 11:28:51 UTC

by Luis Majano

HI Martin, We will be adding hibernate support in the next release. However, you are more than welcome to give it a shot. All the hooks are in place to set this up.

Recent Entries

Must-See ITB 2025 Sessions for TestBox Users!

Must-See ITB 2025 Sessions for TestBox Users!

Are you a fan of TestBox or looking to level up your testing game in 2025? Whether you're just getting started with unit testing or you're already building advanced specs for ColdBox and BoxLang apps, Into the Box 2025 has an exciting lineup tailored just for you. Into the Box 2025 has an exciting lineup tailored just for you. With the recent launch of TestBox 6.3.0 we have amazing new tools, features and tips and tricks to get your testing experience to the next level, review our sessions and test like a pro efficiently and easy!

From hands-on testing strategies to BoxLang innovations, here are the sessions you won’t want to miss this May — and why they matter to you as a TestBox user.

Maria Jose Herrera
Maria Jose Herrera
April 17, 2025
The Into the Box 2025 Agenda is LIVE and Done!

The Into the Box 2025 Agenda is LIVE and Done!

The wait is over! The official Into the Box 2025 agenda is now live — and it's packed with high-impact sessions designed for modern CFML and BoxLang developers. Whether you’re building APIs, modernizing legacy apps, diving into serverless, or exploring AI integrations, this is the conference you’ve been waiting for.

Here’s a look at what you can expect — categorized by key topics to help you plan your learning journey, there’s something for everyone covering modern CFML tools and BoxLang:

Maria Jose Herrera
Maria Jose Herrera
April 15, 2025
Only 2 Days Left to Lock In Early Bird Pricing for Into the Box 2025!

Only 2 Days Left to Lock In Early Bird Pricing for Into the Box 2025!

The countdown is on. You have just two days left to secure your Early Bird ticket  for just $199 to Into the Box 2025 before prices increase on April 16.

We are proud to offer an engaging and high-value online experience for developers around the world. With a virtual ticket, you get more than just access — you get ongoing value that supports your growth long after the conference ends.

Maria Jose Herrera
Maria Jose Herrera
April 14, 2025