java.lang.NoClassDefFoundError: Could not initialize class com.googlecode.objectify.ObjectifyService

java.lang.NoClassDefFoundError: Could not initialize class com.googlecode.objectify.ObjectifyService

这是我的监听器 Class,它注册了我的用户实体。注册我的 POJO class 时发生错误。但是,我的应用程序在本地环境中运行良好。部署到 App Engine 后,我收到服务器错误 500。

@WebListener
public class MyContextListener implements ServletContextListener {

         public void contextDestroyed(ServletContextEvent sce)  {}

         public void contextInitialized(ServletContextEvent sce)  { 
                 ObjectifyService.register(User.class);
          }
    }

下面是我的完整堆栈跟踪

java.lang.NoClassDefFoundError: Could not initialize class com.googlecode.objectify.ObjectifyService
at com.appengine.listener.MyContextListener.contextInitialized (MyContextListener.java:23)
at org.eclipse.jetty.server.handler.ContextHandler.callContextInitialized (ContextHandler.java:843)
at org.eclipse.jetty.servlet.ServletContextHandler.callContextInitialized (ServletContextHandler.java:533)
at org.eclipse.jetty.server.handler.ContextHandler.startContext (ContextHandler.java:816)
at org.eclipse.jetty.servlet.ServletContextHandler.startContext (ServletContextHandler.java:345)
at org.eclipse.jetty.webapp.WebAppContext.startWebapp (WebAppContext.java:1406)
at org.eclipse.jetty.webapp.WebAppContext.startContext (WebAppContext.java:1368)
at org.eclipse.jetty.server.handler.ContextHandler.doStart (ContextHandler.java:778)
at org.eclipse.jetty.servlet.ServletContextHandler.doStart (ServletContextHandler.java:262)
at org.eclipse.jetty.webapp.WebAppContext.doStart (WebAppContext.java:522)
at org.eclipse.jetty.util.component.AbstractLifeCycle.start (AbstractLifeCycle.java:68)
at com.google.apphosting.runtime.jetty9.AppVersionHandlerMap.createHandler (AppVersionHandlerMap.java:244)
at com.google.apphosting.runtime.jetty9.AppVersionHandlerMap.getHandler (AppVersionHandlerMap.java:182)
at com.google.apphosting.runtime.jetty9.JettyServletEngineAdapter.serviceRequest (JettyServletEngineAdapter.java:97)
at com.google.apphosting.runtime.JavaRuntime$RequestRunnable.dispatchServletRequest (JavaRuntime.java:680)
at com.google.apphosting.runtime.JavaRuntime$RequestRunnable.dispatchRequest (JavaRuntime.java:642)
at com.google.apphosting.runtime.JavaRuntime$RequestRunnable.run (JavaRuntime.java:612)
at com.google.apphosting.runtime.JavaRuntime$NullSandboxRequestRunnable.run (JavaRuntime.java:806)
at com.google.apphosting.runtime.ThreadGroupPool$PoolEntry.run (ThreadGroupPool.java:274)
at java.lang.Thread.run (Thread.java:745)

我的应用程序中添加的 JAR 文件

可能这段代码对你有帮助

try {
    Class.forName("com.googlecode.objectify.ObjectifyService");
} catch (ClassNotFoundException e) {
    e.printStackTrace();
}

此代码用于初始化 class

的对象

此代码在继续之前首先尝试加载上述 class。

看起来您正在尝试自己管理依赖项,而不是依赖 pom.xml 中的依赖项信息。很难通过 Whosebug 调试类路径问题。

我建议使用 maven 和 appengine maven 插件。使用 Google 的入门指南创建一个项目,然后添加 Objectify。