Reputation: 13
I tried to compile GWT application, that uses MongoDB and Morphia, but got an exception:
*[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 and MongoDB jars are inserted into Libraries section of Java build path(I'm using Eclipse). Also I've attached MongoDB source code.
When I didn't use Morphia everything worked fine.
Here is my class code:
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;
}
}
What is wrong?
Thanks.
Upvotes: 1
Views: 1255
Reputation: 7590
Morphia GWT support is still under construction.
See this issue: http://code.google.com/p/morphia/issues/detail?id=103
But it seems like you have other issues as well. You cannot connect to a server in shared code, only server code. You need to read and understand what code goes where in a GWT project.
The only thing that the morphia module will support is the ability to send entities down to GWT client code. You cannot actually use it, or the MongoDB driver code, to do server operations at the client; that will never be allowed by GWT.
Upvotes: 3
Reputation: 21300
GWT needs source code of MongoDb and Morphia classes.. But also, you should not and can not use these classes for gwt layer of your application. Also you can not use, java.net package for gwt layer. You can only use a subset of java classes for gwt layer..
I recommend you to read GWT tutorial http://code.google.com/webtoolkit/doc/latest/tutorial/index.html .
Upvotes: 1