Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7906537
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T11:01:14+00:00 2026-06-03T11:01:14+00:00

I’m trying to build some GANT script prior to my Grails Plugin. Basicly, i

  • 0

I’m trying to build some GANT script prior to my Grails Plugin.
Basicly, i want to extend DefaultGrailsTemplateGenerator Class with new Class which add new method to auto generate service class by Grails Templating scheme.

Suppose i’ve named my class with Service generator which extends DefaulGrailsTemplateGenerator and add generateService method.

import org.codehaus.groovy.grails.scaffolding.DefaultGrailsTemplateGenerator;

class ServiceGenerator extends DefaultGrailsTemplateGenerator {
        void generateService(GrailsDomainClass domainClass, String destdir) {
        }
}

All things went normally (e.g GANT Script was called), except in a line of code which i instanstiated ServiceGeneratorClass, it returns error :

Error Error executing script GenerateService: com.cygnus.grails.util.scaffolding.ServiceGenerator
java.lang.NoClassDefFoundError: com.cygnus.grails.util.scaffolding.ServiceGenerator
    at GenerateExt_groovy.class$(GenerateExt_groovy)
    at GenerateExt_groovy.$get$$class$com$cygnus$grails$util$scaffolding$ServiceGenerator(GenerateExt_groovy)
    at GenerateExt_groovy.generateForDomainClass(GenerateExt_groovy:81)

I’ve tried to browse on this error and try to call the class by change the syntax from :

def templateGenerator = new ServiceGenerator(classLoader)

to :

def myClass = classLoader.loadClass("org.my.ServiceGenerator")

Still i found the java.lang.NoClassDefFoundError .
I still couldn’t figure out why this thing could happen.
Can someone help me ?

I attach my GANT Script which calls up Service Generator

/**
 * Gant Script for generating Service Class based on Artifact
 * This Script was used for auto generate service class which is needed to handle basic transactional statements such as:
 * - AuditTrail for tables
 * - Logging before insert / update on tables
 */
includeTargets << grailsScript("_GrailsCreateArtifacts")
includeTargets << new File("${myPluginPluginDir}/scripts/GenerateExt.groovy")



target ('main': "Generates the CRUD service for a specified domain class") {
    depends(checkVersion, parseArguments, packageApp,classpath,configureProxy, 
            loadApp, configureApp, compile)

    promptForName(type: "Domain Class")
    generateViews = false
    generateForName = argsMap["params"][0]
    generateForOne()
}
setDefaultTarget(main)

Any help would be appreciated

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T11:01:16+00:00Added an answer on June 3, 2026 at 11:01 am

    I finally done!

    This is an example of what you want to do: grails-flex-scaffold-script

    And this is my implementation:

    *change $userInterfacePluginDir for your plugin name

    Put this files in scripts:

    GenerateService.groovy

    includeTargets << grailsScript("_GrailsInit")
    includeTargets << grailsScript("_GrailsCreateArtifacts")
    includeTargets << new File("$userInterfacePluginDir/scripts/_GrailsGenerateService.groovy")
    
    target ('default': "Generates the service for a specified domain class") {
    depends(checkVersion, parseArguments, packageApp)
    promptForName(type: "Domain Class")
    generateForName = argsMap["params"][0]
    generateServiceForOne()
    }
    

    _GrailsGenerateService.groovy

    import org.codehaus.groovy.grails.commons.GrailsDomainClass;
    import org.codehaus.groovy.grails.scaffolding.*
    import org.springframework.core.io.AbstractResource;
    import org.springframework.core.io.FileSystemResource;
    import grails.util.GrailsNameUtils
    
    /**
     * Gant script that generates a service for a given domain class
     *
     * @author Martín Caballero
     *
     */
    
    includeTargets << grailsScript("_GrailsBootstrap")
    
    generateForName = null
    
    target(generateServiceForOne: "Generates service for only one domain class.") {
        depends(loadApp)
    
        def name = generateForName
        name = name.indexOf('.') > 0 ? name : GrailsNameUtils.getClassNameRepresentation(name)
        def domainClass = grailsApp.getDomainClass(name)
    
        if (!domainClass) {
            grailsConsole.updateStatus "Domain class not found in grails-app/domain, trying hibernate mapped classes..."
            bootstrap()
            domainClass = grailsApp.getDomainClass(name)
        }
    
        if (domainClass) {
            generateServiceForDomainClass(domainClass)
            event("StatusFinal", ["Finished generation for domain class ${domainClass.fullName}"])
        }
        else {
            event("StatusFinal", ["No domain class found for name ${name}. Please try again and enter a valid domain class name"])
            exit(1)
        }
    }
    
    def generateServiceForDomainClass(domainClass) {
        UserInterfaceTemplateGenerator = classLoader.loadClass('plugin.ui.scaffold.UserInterfaceTemplateGenerator')
        def templateGenerator = UserInterfaceTemplateGenerator.newInstance(classLoader)
        templateGenerator.grailsApplication = grailsApp
        templateGenerator.pluginManager = pluginManager
    
        event("StatusUpdate", ["Generating service for domain class ${domainClass.fullName}"])
        templateGenerator.generateService(domainClass, basedir)
        event("GenerateServiceEnd", [domainClass.fullName])
    }
    

    UserInterfaceTemplateGenerator: (helper class – extends DefaultGrailsTemplateGenerator)

    package plugin.ui.scaffold
    
    import org.codehaus.groovy.grails.scaffolding.DefaultGrailsTemplateGenerator;
    import grails.build.logging.GrailsConsole
    import grails.util.BuildSettingsHolder
    import groovy.text.SimpleTemplateEngine
    import groovy.text.Template
    import org.apache.commons.logging.Log
    import org.apache.commons.logging.LogFactory
    import org.codehaus.groovy.grails.commons.GrailsApplication
    import org.codehaus.groovy.grails.commons.GrailsDomainClass
    import org.codehaus.groovy.grails.plugins.GrailsPluginManager
    import org.codehaus.groovy.grails.plugins.PluginManagerAware
    import org.springframework.context.ResourceLoaderAware
    import org.springframework.core.io.ClassPathResource
    import org.springframework.core.io.FileSystemResource
    import org.springframework.core.io.ResourceLoader
    import org.springframework.core.io.support.PathMatchingResourcePatternResolver
    import org.springframework.util.Assert
    import org.springframework.core.io.AbstractResource
    import org.codehaus.groovy.grails.scaffolding.SimpleDomainClassPropertyComparator
    import org.codehaus.groovy.grails.scaffolding.DomainClassPropertyComparator
    
    class UserInterfaceTemplateGenerator extends DefaultGrailsTemplateGenerator {
        public UserInterfaceTemplateGenerator(ClassLoader classLoader){
            super(classLoader)
        }
    
        void generateService(GrailsDomainClass domainClass, String destdir) {
            Assert.hasText destdir, "Argument [destdir] not specified"
    
            if (domainClass) {
                def fullName = domainClass.fullName
                def pkg = ""
                def pos = fullName.lastIndexOf('.')
                if (pos != -1) {
                    // Package name with trailing '.'
                    pkg = fullName[0..pos]
                }
    
                def destFile = new File("${destdir}/grails-app/services/${pkg.replace('.' as char, '/' as char)}${domainClass.shortName}Service.groovy")
                if (canWrite(destFile)) {
                    destFile.parentFile.mkdirs()
    
                    destFile.withWriter { w ->
                        generateService(domainClass, w)
                    }
    
                    LOG.info("Controller generated at ${destFile}")
                }
            }
        }
    
        void generateService(GrailsDomainClass domainClass, Writer out) {
            def templateText = getTemplateText("Service.groovy")
    
            boolean hasHibernate =pluginManager?.hasGrailsPlugin('hibernate')
            def binding = [pluginManager: pluginManager,
                           packageName: domainClass.packageName,
                           domainClass: domainClass,
                           className: domainClass.shortName,
                           propertyName: getPropertyName(domainClass),
                           comparator: hasHibernate ? DomainClassPropertyComparator : SimpleDomainClassPropertyComparator]
    
            def t = engine.createTemplate(templateText)
            t.make(binding).writeTo(out)
        }
    
        protected canWrite(File testFile) {
            if (!overwrite && testFile.exists()) {
                try {
                    def response = GrailsConsole.getInstance().userInput("File ${makeRelativeIfPossible(testFile.absolutePath, basedir)} already exists. Overwrite?",['y','n','a'] as String[])
                    overwrite = overwrite || response == "a"
                    return overwrite || response == "y"
                }
                catch (Exception e) {
                    // failure to read from standard in means we're probably running from an automation tool like a build server
                    return true
                }
            }
            return true
        }
    
        protected String getPropertyName(GrailsDomainClass domainClass) { "${domainClass.propertyName}${domainSuffix}" }
    
    }
    

    And, finally, this is my template: (Put it in src/templates/scaffolding/)

    Service.groovy

    <%import org.codehaus.groovy.grails.commons.GrailsClassUtils;%>
    <%=packageName ? "package ${packageName}\n\n" : ''%>
    class ${className}Service {
    
        def getTable() {
            def query = {
                <%
                    def searchFields = GrailsClassUtils.getStaticPropertyValue(domainClass.clazz, 'search' )
                    if(searchFields)
                    {
                %>
                        if (params.q) {
                            or{
                            <%searchFields.each { field ->%>
                                ilike("${field}", '%' + params.q + '%')
                            <%}%>
                            }
                        }
                <%  }   %>
                if (params.sort){
                    order(params.sort,params.order)
                }
            }
            def criteria = ${className}.createCriteria()
            return criteria.list(query, max: params.max, offset: params.offset)
        }
    }
    

    Then, you use the command as “grails generate-service yourdomainclass”

    Hope that helps!

    This is the essential of the answer:

    UserInterfaceTemplateGenerator = classLoader.loadClass('plugin.ui.scaffold.UserInterfaceTemplateGenerator')
    def templateGenerator = UserInterfaceTemplateGenerator.newInstance(classLoader)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want use html5's new tag to play a wav file (currently only supported
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am trying to render a haml file in a javascript response like so:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.