无法通过谷歌应用引擎运行应用程序

时间:2013-05-14 19:28:55

标签: java google-app-engine

我一直关注this tutorial

使用Google App Engine创建待办事项列表应用。当我去部署它时,我得到了这个错误

java.lang.ExceptionInInitializerError:

通过查看控制台中的输出,它链接到我的代码中的以下行

EntityManager em = EMFService.get().createEntityManager();

我在这个网站上看到了类似的东西,但没有解决方案。以下是与错误相关的类

Dao.Java

public enum Dao {
INSTANCE;

@SuppressWarnings("unchecked")
public List<Todo> listTodos() {

    EntityManager em = EMFService.get().createEntityManager();
    Query q = em.createQuery("select m from Todo m");
    List<Todo> todos = q.getResultList();
    return todos;
}

public void add(String userID, String summery, String description, String url) {

    synchronized(this) {

        EntityManager em = EMFService.get().createEntityManager();
        Todo todo = new Todo( userID, summery, description, url );
        em.persist(todo);
        em.close();

    }
}

@SuppressWarnings("unchecked")
public List<Todo> getTodo(String userID) {

    EntityManager em = EMFService.get().createEntityManager(); // Error links to here
    Query q = em.createQuery("select t from Todo t where t.author = :userID");
    q.setParameter("userID", userID);
    List<Todo> todos = q.getResultList();

    return todos;
}

public void remove(long id) {

    EntityManager em = EMFService.get().createEntityManager();

    try {
        Todo todo = em.find(Todo.class, id);
        em.remove(todo);
    } finally {
        em.close();
    }
}
}

EMFService.java

public class EMFService {

private static final EntityManagerFactory emfInstance = Persistence.createEntityManagerFactory("transactions-optional");

private EMFService() {}

public static EntityManagerFactory get() {
    return emfInstance;
}
}

非常感谢任何帮助。

控制台输出

WARNING: Nested in javax.servlet.ServletException: java.lang.NoClassDefFoundError:        Could not initialize class com.chrismcnulty.gaetutorial.EMFService:
java.lang.NoClassDefFoundError: Could not initialize class      com.chrismcnulty.gaetutorial.EMFService
at com.chrismcnulty.gaetutorial.Dao.getTodo(Dao.java:35)
at org.apache.jsp.TodoApplication_jsp._jspService(TodoApplication_jsp.java:92)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:97)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:377)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
at com.google.appengine.tools.development.PrivilegedJspServlet.access$101(PrivilegedJspServlet.java:23)
at com.google.appengine.tools.development.PrivilegedJspServlet$2.run(PrivilegedJspServlet.java:61)
at java.security.AccessController.doPrivileged(Native Method)
at com.google.appengine.tools.development.PrivilegedJspServlet.service(PrivilegedJspServlet.java:58)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:511)
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1166)
at com.google.appengine.api.socket.dev.DevSocketFilter.doFilter(DevSocketFilter.java:74)
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
at com.google.appengine.tools.development.ResponseRewriterFilter.doFilter(ResponseRewriterFilter.java:123)
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
at com.google.appengine.tools.development.HeaderVerificationFilter.doFilter(HeaderVerificationFilter.java:34)
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
at com.google.appengine.api.blobstore.dev.ServeBlobFilter.doFilter(ServeBlobFilter.java:61)
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
at com.google.apphosting.utils.servlet.TransactionCleanupFilter.doFilter(TransactionCleanupFilter.java:43)
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
at com.google.appengine.tools.development.StaticFileFilter.doFilter(StaticFileFilter.java:125)
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
at com.google.appengine.tools.development.DevAppServerServersFilter.doFilter(DevAppServerServersFilter.java:106)
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:388)
at org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:216)
at org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:182)
at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:765)
at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:418)
at com.google.appengine.tools.development.DevAppEngineWebAppContext.handle(DevAppEngineWebAppContext.java:94)
at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
at com.google.appengine.tools.development.JettyContainerService$ApiProxyHandler.handle(JettyContainerService.java:421)
at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
at org.mortbay.jetty.Server.handle(Server.java:326)
at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:542)
at org.mortbay.jetty.HttpConnection$RequestHandler.headerComplete(HttpConnection.java:923)
at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:547)
at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:212)
at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:404)
at org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:409)
at org.mortbay.thread.QueuedThreadPool$PoolThread.run(QueuedThreadPool.java:582)

1 个答案:

答案 0 :(得分:0)

实际上,它可能因为无法初始化EMFService类而受到限制。加载类时初始化静态成员。实际上失败的那条线就是:

private static final EntityManagerFactory emfInstance = Persistence.createEntityManagerFactory("transactions-optional");

“交易 - 可选”可能是错误的吗?