1
你好我正在使用GWT的EclipseLink和hsqldp一個項目的源代碼,但我得到這個:GWT找不到我的課
[ERROR] [myproject]: No source code is available for type it.myproject.server.CreateEmployee; did you forget to inherit a required module?
好像日食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' />
所以你認爲我必須刪除project.java中的「import it.myproject.server.CreateEmployee;」導致文件使用服務器端的3持久性導入? 在這種情況下,我怎樣才能在myproject.java中調用createNewEmployee()方法? – user2298581
你自己回答了:import it.myproject.server.CreateEmployee; 包括包服務器。千萬不要在gwt的客戶端包中創建一個服務器類。 –
謝謝answear!那麼你如何建議調用一個包服務器的方法[CreateEmployee.createNewEmployee()];在onmoduleload()如果我不能導入文件「import it.myproject.server.CreateEmployee;」? – user2298581