grailstaglibgrails-2.4run-script

How to access taglib in scripts meant for run-script?


How to access ApplicationTagLib in a script meant for the grails command line run-script?

In case someone wonders what is the use case

This problem came up when I was trying to create a script for generating a json file (containing links to controllers and actions) for use in javascript files. More info in https://stackoverflow.com/questions/30763227/how-to-use-urls-rendered-as-javascript-variables-during-jasmine-unit-tests

I was considering using g.createLink in this script file but couldn't find how to use tag library in script file.


Solution

  • You can use below code to access your taglib

    def grailsApplication 
    def g = grailsApplication.mainContext.getBean('org.codehaus.groovy.grails.plugins.web.ta‌​glib.ApplicationTagLib')