我尝试编译使用 MongoDB 和 Morphia 的 GWT 应用程序,但出现异常:
*[ERROR] - Line 12: No source code is available for type com.google.code.morphia.Morphia; did you forget to inherit a required module?
[ERROR] - Line 13: No source code is available for type com.mongodb.DB; did you forget to inherit a required module?
[ERROR] - Line 15: No source code is available for type java.net.UnknownHostException; did you forget to inherit a required module?
[ERROR] - Line 15: No source code is available for type com.mongodb.MongoException; did you forget to inherit a required module?
[ERROR] - Line 17: No source code is available for type com.mongodb.Mongo; did you forget to inherit a required module?
[ERROR] - Line 27: No source code is available for type com.mongodb.DBCollection; did you forget to inherit a required module?*
Morphia 和 MongoDB jar 被插入到 Java 构建路径的库部分(我使用的是 Eclipse)。我还附上了 MongoDB 源代码。
当我不使用 Morphia 时,一切正常。
这是我的课程代码:
package com.planner.shared;
import java.net.UnknownHostException;
import java.util.ArrayList;
import com.google.code.morphia.Morphia;
import com.mongodb.*;
import com.planner.shared.Project;
import com.planner.shared.ClassWrapper;
public class ProjectWrapper extends Base implements ClassWrapper {
Morphia morphia;
DB db;
public ProjectWrapper() throws UnknownHostException, MongoException {
super();
Mongo m = new Mongo("127.0.0.1", 27017);
db = m.getDB("planner");
morphia = new Morphia();
morphia.map(Project.class);
}
public ArrayList<Project> getProjects() {
ArrayList<Project> projects = new ArrayList<Project>();
//Get projects collection
DBCollection projectsColl = db.getCollection("projects");
//Get all projects from collection
DBCursor cur = projectsColl.find();
//Save all project to arrayList
while(cur.hasNext()) {
DBObject obj = cur.next();
projects.add(morphia.fromDBObject(Project.class, obj));
}
return projects;
}
}
怎么了?
谢谢。