Over a million developers have joined DZone.
Platinum Partner

How to Create Modular Groovy Applications in 5 Steps!

· Java Zone

The Java Zone is brought to you in partnership with ZeroTurnaround. Discover how you can skip the build and redeploy process by using JRebel by ZeroTurnaround.

Let's create a modular Groovy application! Why?! Modularity is an enabler of scaleability. As your Groovy application increases in size, you increasingly need to manage code dependencies, structure your code in units that are larger than packages, and distribute pieces of your application to developers located in different locations and conflicting time zones. Welcome to modularity.

The NetBeans Platform already provides it (plus, OSGi is coming to the NetBeans Platform). Beyond modularity, there are specific features that the NetBeans Platform provides that will remain unique, such as a shared filesystem for intermodular communication and the concept of "context" (i.e., NetBeans Lookup), which not only applications have (as with the JDK 6 ServiceLoader class), but NetBeans Platform objects such as windows themselves. Welcome to loosely coupled modularity.

Now, let's get started.

  1. Start up NetBeans IDE 6.5.

  2. Go to this page and download the Groovy Console Template and use the Plugin Manager (in the Tools menu) to install it into the IDE.

  3. Now, in the New Project dialog, you should see this new project template:

  4. Click Next, give your new application a name (such as "HelloWorld") and a location on disk, and then click Finish. Expand a few folders and you should now see this:

    Briefly, the template gives you a Groovy POJO, with this content:

    package org.my.app

    public class DemoPojo {

    def foo


    The template also gives you a ModuleInstall class, which handles the lifecycle of the module:

    package org.my.app

    import org.openide.modules.ModuleInstall as MI

    public class Installer extends MI {

    public void restored() {

    for(int i = 0; i < 10; i++) {
    DemoPojo dp = new DemoPojo()
    println("Number: " + dp.getFoo())



    So, we have some standard Groovy constructs here, simply to get you started in the ecosystem of the NetBeans Platform. The module also includes a properties file for internationalization purposes and a layer.xml file, for the module's contributions to the shared filesystem.

  5. Run the application (i.e., without doing anything at all, no tweaking, no post processing, nothing at all, just run it). Look in the Output window of NetBeans IDE and you will see this:

So, you can see that you only have the absolute minimum set of modules to start with. Also you're using the Groovy compiler (thanks to an additional target that's added to the demo module's build.xml file). That's how to get started with modular Groovy applications. Have fun with Groovy on the NetBeans Platform!


The Java Zone is brought to you in partnership with ZeroTurnaround. Discover how you can skip the build and redeploy process by using JRebel by ZeroTurnaround.


{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}