您好我正在使用GWT eclipselink和hsqldp开展项目,但我得到了这个:
[ERROR] [myproject]: No source code is available for type it.myproject.server.CreateEmployee; did you forget to inherit a required module?
似乎eclipse gwt无法找到我的类CreateEmployee甚至认为我把正确的导入..!
这是代码(CreateEmployee.java):
package it.myproject.server;
import it.myproject.shared.entity.Employee;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;
public class CreateEmployee {
public static void createNewEmployee() {
EntityManagerFactory emf = Persistence.createEntityManagerFactory("ronfPU");
EntityManager em = emf.createEntityManager();
try {
Employee e1= new Employee();
e1.setUsername("admin");
e1.setPassword("admin");
em.persist(e1);
em.getTransaction().commit();
} finally {
em.close();
}
}
}
这是myproject.java的主文件:
package it.myproject.client;
import it.myproject.server.CreateEmployee;
import it.myproject.shared.entity.Employee;
import com.google.gwt.core.client.EntryPoint;
public class myproject implements EntryPoint {
@Override
public void onModuleLoad() {
try{
new CreateEmployee();
CreateEmployee.createNewEmployee();
} catch (Exception e) {
Window.alert("creation of employees failed");
}
[....here 's some others useless codes..]
}
thoose是我的源路径(myproject.gwt.xml):
<!-- Specify the paths for translatable code -->
<source path='client' />
<source path='shared' />
答案 0 :(得分:1)
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;
不是客户端gwt标准库的一部分。您必须删除它,或者您必须继承gwt-project中的库(但我不认为有这样的库)。
你CreateEmployee
类应该是纯服务器逻辑,而不是客户端。