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
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
_GrailsGenerateService.groovy
UserInterfaceTemplateGenerator: (helper class – extends DefaultGrailsTemplateGenerator)
And, finally, this is my template: (Put it in src/templates/scaffolding/)
Service.groovy
Then, you use the command as “grails generate-service yourdomainclass”
Hope that helps!
This is the essential of the answer: