Grails 上的 NoClassDefFoundError GANT 脚本
我正在尝试在 Grails 插件之前构建一些 GANT 脚本。 基本上,我想用新类扩展 DefaultGrailsTemplateGenerator 类,该类添加新方法以通过 Grails 模板方案自动生成服务类。
假设我用服务生成器命名了我的类,它扩展了 DefaultGrailsTemplateGenerator 并添加了generateService 方法。
import org.codehaus.groovy.grails.scaffolding.DefaultGrailsTemplateGenerator;
class ServiceGenerator extends DefaultGrailsTemplateGenerator {
void generateService(GrailsDomainClass domainClass, String destdir) {
}
}
一切正常(例如调用了 GANT 脚本),除了在我实例化 ServiceGeneratorClass 的一行代码中,它返回错误:
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)
我尝试浏览此错误并尝试通过将语法从 : 更改
def templateGenerator = new ServiceGenerator(classLoader)
为 : 来调用
def myClass = classLoader.loadClass("org.my.ServiceGenerator")
该类我仍然发现了 java.lang.NoClassDefFoundError 。 我仍然不明白为什么会发生这种事。 有人可以帮助我吗?
我附上我的 GANT 脚本,它调用服务生成器
/**
* 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)
任何帮助将不胜感激
谢谢
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我终于完成了!
这是您想要执行的操作的示例: grails- flex-scaffold-script
这是我的实现:
*将 $userInterfacePluginDir 更改为您的插件名称
将此文件放入脚本中:
GenerateService.groovy
_GrailsGenerateService.groovy
UserInterfaceTemplateGenerator:(帮助程序类 - 扩展 DefaultGrailsTemplateGenerator)
最后,这是我的模板:(将其放入 src/templates/scaffolding/)
Service.groovy
然后,您使用命令“grailsgenerate-service yourdomainclass”
希望这有帮助!
这是答案的要点:
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: