Console Plugin
4% of Grails users
Dependency :
compile ":console:1.2"
Summary
A web-based Groovy console for interactive runtime application management and debugging
Installation
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
Description
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 - GrailsApplication instance, e.g.
grailsApplication.domainClasses.each {
println "There are ${it.clazz.count()} instances of $it.clazz.simpleName"
}- ctx - Spring ApplicationContext, e.g.
import groovy.sql.Sqldef dataSource = ctx.dataSource def sql = Sql.newInstance(dataSource) sql.eachRow("select * from information_schema.system_tables", { println it.TABLE_NAME })
- session - the current HTTP session
session.attributeNames.each { name ->
println name.padRight(40) + session.getAttribute(name)
}- request - the current HTTP request, e.g.
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
printlnstatements 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.
Reference
- The code editor is powered by CodeMirror
Development
- The source code for the plugin is available at https://github.com/burtbeckwith/grails-console
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