Skip to content

Martini Services Creating Groovy Classes

Creating a Groovy service in Martini is a streamlined process. This guide will walk you through the steps to set up your Groovy-based service within the Martini platform.

Steps to Create a Groovy Service

  1. Select the Location:

    • Navigate to your target Martini package, specifically the code directory or any subdirectory where you want your Groovy service.
    • Right-click and select New > Groovy Class.
  2. Define Class Properties:

    • Input the class name for your Groovy service.
    • Optionally, you can adjust the following properties in the creation wizard:
      • Location: By default, it is set to the current directory. You can change it if needed.
      • Kind: Choose the type of Groovy file – class, interface, enum, annotation, etc.
      • Modifiers: Define the access modifiers for your Groovy class.
  3. Create the Service:

    • Click Finish to create the Groovy file. Martini will open the file in the Groovy editor.
    • Start coding your service. Remember to save the file to apply changes.

Compilation Requirements

For successful compilation of your Groovy service in Martini, please observe the following rules:

  • Class-File Name Consistency:

    • Ensure the Groovy class name matches the filename. For instance, Employee.groovy should declare a class named Employee.
    1
    2
    3
    class Employee {
        // ...
    }
    
  • Single Top-Level Class Rule:

    • Each .groovy file should contain only one top-level class. Avoid declaring multiple top-level classes in a single file.
     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    // Correct Usage
    class ValidClass {
        // ...
    }
    
    // Incorrect Usage
    class FirstClass {
        // ...
    }
    class SecondClass {
        // ...
    }
    
  • Package-Directory Alignment:

    • The package declared in the Groovy file should correspond to its directory location.

In case of compilation errors, your code will still be saved, but it won't be executable with other application components until the issues are resolved.

Additional Tips

  • Changing Class Type:
    • While naming your class in the wizard, you can switch the class type (e.g., class, interface, enum) using the provided options.

Following these steps and guidelines ensures that your Groovy services are correctly set up in Martini, facilitating smooth integration and execution within your applications.

Efficient Development Practices

Frequently test and save your Groovy scripts during development to catch and fix errors early, ensuring seamless integration with Martini's other components.