Sign in to edit and +1 items.
Login required
Download

Web-based Groovy Console for Grails

(11)
Used by approximately
4%
of Grails users
Author(s) Siegfried Puchbauer/Mingfai Ma
Current Release 1.1   (3 months ago)
Grails Version 1.1 > *
Tags commandline  configuration  development  management 
Dependency
compile ":console:1.1"
A web-based Groovy console for interactive runtime application management and debugging
Last updated by ziegfried 3 years ago

Installation

  • in command prompt, under your project directory
    grails install-plugin console
  • access the console under ${contextPath}/console, e.g. http://localhost:8080/consoleDemo/console
Last updated by burtbeckwith 3 months ago

Usage

  • Run your web application using grails run-app, then use a browser to navigate to the /console page of your app - most likely http://localhost:8080/<app-name>/console
  • Type any Groovy commands in the console text area, then press "Execute"
  • Keyboard Shortcuts:
    • Ctrl + Enter - Execute
    • Esc - Clear output
  • The following implicit variables are available:
grailsApplication.domainClasses.each {
   println "There are ${it.clazz.count()} instances of $it.clazz.simpleName"
}
import groovy.sql.Sql

def dataSource = ctx.dataSource def sql = Sql.newInstance(dataSource) sql.eachRow("select * from information_schema.system_tables", { println it.TABLE_NAME })

session.attributeNames.each { name ->
   println name.padRight(40) + session.getAttribute(name)
}
def params = ['requestURI', 'requestURL', 'forwardURI']
params.each {
   println it + "\t" + request."$it"
}
    • config - the current Grails config, e.g.
config.flatten().each { name, value ->
   println name.padRight(40) + value
}
  • Result Area
    • The results area displays the output of println statements and the return value of the last line executed (in blue).
    • Exceptions are also shown in the results area but with a red background
    • Additionally the execution time of your script is shown along with the output or exception

Concepts

  • The console plugin relies on Groovy Shell. Lookup Groovy Shell documentation for more information.
  • The Groovy Shell uses the Grails classloader, so you can access any class or artifact (e.g. domain classes, services, etc.) just like in your application code.

Security Warning

  • IMPORTANT In the current version, no security feature is implemented and the '/console' path is accessible from anywhere. You're strongly encouraged to guard access to the console using a security plugin, for example Spring Security Core or Shiro.

Compatibility

  • This plugin works with all recent versions of Grails (1.1 or higher).

Reference

Development

Questions, issues, etc.

  • If have questions or suggestions about the plugin, ask on the Grails User mailing list. Report bugs in JIRA.

Authors

  • Siegfried Puchbauer
  • Mingfai Ma
  • Burt Beckwith
  • Matt Sheehan
  • Mike Hugo
Last updated by bryanchug 3 weeks ago
How to customize the default code?

Add a filter:

consoleFilter(controller: 'console'){
    before = {
        if( !session['_grails_console_last_code_'] ){
            session['_grails_console_last_code_'] = '''import com.foo.bar.domain.*

''' } }

Last updated by burtbeckwith 1 year ago
Here's an example of running some code in the console:

and here's an example of when an exception is thrown during script execution: