【发布时间】:2014-04-10 19:00:19
【问题描述】:
我正在尝试在 grails 2.3.6 脚本中创建域类的实例:
def player = new Player(name:"Bob")
player.save()
但我不断收到异常
java.lang.NoClassDefFoundError: gaming/Player
我已经尝试了我在互联网上找到的所有不同的引导技巧,但它们并没有真正改变结果:
我尝试过导入:
import gaming.Player
我已经尝试加载引导脚本:
includeTargets << grailsScript("_GrailsBootstrap")
我已根据我设法找到的每项任务进行了尝试:
depends(configureProxy, packageApp, classpath, loadApp, configureApp, compile, bootstrap)
我什至尝试在运行时加载类:
ApplicationHolder.application.getClassForName("gaming.Player")
有趣的是,最后一行并没有表明 grails 可以找到我的类,但在我实际使用它时选择忽略该查找。
编辑。根据要求,这是脚本的当前版本
import gaming.Player
import org.codehaus.groovy.grails.commons.ApplicationHolder
includeTargets << grailsScript("_GrailsInit")
includeTargets << grailsScript("_GrailsBootstrap")
includeTargets << grailsScript("_GrailsClasspath")
def handleHeaderLine(line) {
def retval = []
line.each {
if(!it.equals("Game Name") && !it.equals("Total # of Copies")) {
println("Creating Player: " + it)
def player = new Player(name:it)
player.save
retval << it
} else {
retval << null
}
}
return retval;
}
def handleGameLine(header, line) {
println("Creating Game: " + line[0])
for(int i = 1; i < line.length - 1; i++) {
if(!header[i].equals("Total # of Copies")) {
def count = line[i] == "" ? 0 : Integer.parseInt(line[i]);
for(int j = 0; j < count; j++) {
println "Creating copy of " + line[0] + " owned by " + header[i]
}
}
}
}
target(loadAssets: "The description of the script goes here!") {
depends(configureProxy, packageApp, classpath, loadApp, configureApp, compile, bootstrap)
ApplicationHolder.application.getClassForName("gaming.Player")
def tsv = new File("...")
def header = null;
tsv.eachLine {
def line = it.split("\t")
if(header == null) {
header = handleHeaderLine(line)
println header
} else {
handleGameLine(header, line)
}
}
}
setDefaultTarget(loadAssets)
【问题讨论】:
-
尝试添加 includeTargets
-
它已经存在(作为 grails create-script 的一部分)。
-
能否提供您的
Gant脚本
标签: grails dns bootstrapping