1
我是新的Scala,我正在寫一個簡單的rss閱讀器。 我有班級經理管理飼料和內容。附加列表[數據庫]
package lib
import scala.xml._
import java.net.URL
import net.liftweb.couchdb.{CouchDB, Database}
import dispatch.{Http, StatusCode}
/**
* @author smix
*
* Feeds manager
*/
object Manager {
var db = List[Database]()
/*
* Initialize CouchDb databases
*/
def init = {
this.appendDb(new Database("myserver.com", 5984, "content"))
}
/*
* Append a new database to the databases list
*/
private def appendDb(database: Database) : Unit = {
database :: db
// Strange exception if database has been already created
/* try {
this.db.head.createIfNotCreated(new Http())
} catch {
case e:java.lang.NoClassDefFoundError => {}
} */
}
/*
* Fetch articles from feed by url
*/
def fetchItems(feedUrl: String): List[scala.xml.Elem] = {
val rssFeed = XML.load((new URL(feedUrl)).openConnection.getInputStream)
val items = rssFeed \ "channel" \ "item"
val articles: List[scala.xml.Elem] = List()
for(item <- items) {
item :: articles
}
articles
}
}
我想將內容存儲在CouchDb中。我需要有沙發數據庫列表(飼料,文章等)。我寫的類,但是當我打電話appendDb我得到一個錯誤:
Exception in thread "main" java.lang.NoClassDefFoundError: lib/Manager$
at collector$.main(collector.scala:5)
at collector.main(collector.scala)
Caused by: java.lang.ClassNotFoundException: lib.Manager$
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
... 2 more
當我rewrited db
定義:var db = List[Int]()
和appendDb的第一行:1 :: this.db
項目運行良好......奇怪。
另外,有趣的是,爲什麼當我爲現有數據庫(appendDb中的註釋try-catch塊)調用createIfNotCreated時,我得到異常。
謝謝。我會嘗試找到缺少的jar ... – 2010-08-01 13:06:01