Skip to content

Toro Cloud Dev Center


Creating a Groovy service

Just follow the steps below to create your own Groovy service:

Creating a Groovy service

Creating a Groovy service

  1. Under your target Martini package, right click on the code directory or any of the packages underneath it where you'd like your Groovy service to reside, and then choose New > Groovy Class.
  2. Enter the file name (class name) of your Groovy service. You will also be given the option to change the values of the following fields in the wizard:

    • Location - where the to-be-created Groovy service will reside; the default value is the folder where you did the right click
    • Kind - the type of Groovy file you'll be creating – class, interface, enum, annotation, etc.
    • Modifiers - the modifiers of your Groovy class
  3. Click Finish. At this point, your Groovy file should have been created for you.

Martini will automatically open the Groovy file in the Groovy editor where you can code your application requirements. Save your file for the changes to take effect.

Change the class type using arrow keys

In Martini Desktop, while you're editing the name of the class in the wizard, you can use the up and down arrow keys to choose its type (e.g. class, interface, enum).

Compilation requirements

For your code to compile, Martini requires that you observe the following additional rules1:

  • If you're going to create a Groovy class (as opposed to a script), the name of the file and class must be the same. For example, a file named Employee.groovy should have its class declared like so:

    1
    2
    3
    class Employee {
        // ...
    }
    
  • There should only be a single top-level class in each .groovy file. This means the following is invalid:

    1
    2
    3
    4
    5
    6
    7
    class One {
        // ...
    }
    
    class Two {
        // ...
    }
    
  • The declared package name and the directory where the Groovy file is located should match.

Even if your code fails to compile, what you wrote will still be saved; but because compilation failed, this means that you won't be able to use your class or script with other application components.


  1. Aside from the requirements of the native Groovy compiler