我想創建一個Grails內域類的實例2.3.6腳本里面:創建一個域類的一個實例,一個Grails腳本
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 << grailsScript( 「_ GrailsInit」) –
它已經存在(如Grails的一部分創建腳本)。 – spierepf
你能否提供你的'Gant'腳本 – emilan