2012-04-23 9 views
0

netbeansを使用してスクリプトフォルダに次のスクリプトを作成しました。私はドメインクラスを保存できません。また、プロジェクト全体をwarファイルとして展開する場合は、Windowsスケジューラを使用してスクリプトを実行できますか?Groovy Script save domainクラス

スクリプト

def json = "" 
def txt = new URL("http://free.worldweatheronline.com/feed/weather.ashx?q=Singapore,Singapore&format=xml&num_of_days=1&key=b674fb7e94131612112609").text 
def records = new XmlSlurper().parseText(txt) 
def weather = records.weather 
def dates = weather.date 
def min = weather.tempMinC 
def max = weather.tempMaxC 
def img = weather.weatherIconUrl 
def desc = weather.weatherDesc 
def descLink = desc.toString().replaceAll(" ","%20") 
println max 
Weathers w = new Weathers() 
w.cityName="singapore" 
w.day = dates 
w.description =desc 
w.max = max 
w.img = img 
w.min = min 
w.url = "jk" 

ドメインクラス

package org.mPest 

class Weathers { 
    int id 
    String day 
    String min 
    String max 
    String img 
    String description 
    String cityName 
    String url 

static constraints = { 
    id(blank:false, unique:true) 
    cityName(blank:false) 
    url(blank:false) 

} 

}あなたが直接ドメインクラスを使用することはできません

答えて

0

src/groovyからドメインクラスを使用する方法を読むためにthis FAQを参照してください:

import org.codehaus.groovy.grails.commons.ApplicationHolder 
//… 
def book = ApplicationHolder.application.getClassForName("library.Book").findByTitle("Groovy in Action") 

それが可能ならば、私は窓から戦争パックスクリプトを実行するのか分からないけど、あなたのタスクをスケジュールするためにGrailsのQuartz pluginを使用することができます...

0

grails run-script commandをご覧ください。 Windowsスケジューラやcronのようなものを使ってスクリプトを実行することができるはずですが、スクリプトの実行に使用できる完全なソースコード(warファイルではない)を持っていなければなりません。

0

Grails 2.xでは、ApplicationHolderの代わりにHoldersを使用する必要があります。例:

import grails.util.Holders 
def validKeys = Holders.grailsApplication.getClassForName("com.vcd.Metadata").findAll { it.metadataKey }*.metadataKey 
関連する問題