- Grails Tutorial
- Grails - Home
- Grails - Overview
- Grails - MVC Architecture
- Grails - Creating an Application
- Grails - The Command Line
- Grails - Application Profiles
- Object Relational Mapping (GORM)
- Grails - The Web Layer
- Grails - Groovy Server Pages
- Grails - Web Services
- Grails - Validation
- Grails - Plugins
Grails - Creating Custom Scripts and Commands
Description
You can create your own custom script by using the create-script as shown below.
project_directory> grails create-script my-script
When you run the above command, it will create a script under src\main\scripts\my-script.groovy folder and my-script.groovy file contains below code:
description "Example description", "grails example-usage" println "Welcome to Tutorialspoint!!!"
You can run the script by using the below command:
project_directory> grails my-script
It will produce the output as shown below:
You can create your own custom command by using the create-command as shown below.
project_directory> grails create-command mycommand
When you run the above command, it will create a command under grails-app/commands/helloworld/MycommandCommand.groovy folder the MycommandCommand.groovy file contains below code:
package helloworld import grails.dev.commands.* class MycommandCommand implements GrailsApplicationCommand { boolean handle() { return false } }
The commands which are created, implements the GrailsApplicationCommand trait by default and uses the boolean handle() method to implement the command.
Advertisements
To Continue Learning Please Login
Login with Google