java.lang.NoClassDefFoundError : com/googlecode/objectify/ObjectifyService

标签 java eclipse google-app-engine objectify

我尝试在 Appengine 上运行我的项目,但是当我进入登录页面时,我收到 500 错误和以下堆栈:

    2014-02-07 04:37:02.656
Uncaught exception from servlet
java.lang.NoClassDefFoundError: com/googlecode/objectify/ObjectifyService
    at com.appspot.darkening.server.UserContextListener.contextInitialized(UserContextListener.java:33)
    at org.mortbay.jetty.handler.ContextHandler.startContext(ContextHandler.java:548)
    at org.mortbay.jetty.servlet.Context.startContext(Context.java:136)
    at org.mortbay.jetty.webapp.WebAppContext.startContext(WebAppContext.java:1250)
    at org.mortbay.jetty.handler.ContextHandler.doStart(ContextHandler.java:517)
    at org.mortbay.jetty.webapp.WebAppContext.doStart(WebAppContext.java:467)
    at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:50)
    at com.google.apphosting.runtime.jetty.AppVersionHandlerMap.createHandler(AppVersionHandlerMap.java:219)
    at com.google.apphosting.runtime.jetty.AppVersionHandlerMap.getHandler(AppVersionHandlerMap.java:194)
    at com.google.apphosting.runtime.jetty.JettyServletEngineAdapter.serviceRequest(JettyServletEngineAdapter.java:134)
    at com.google.apphosting.runtime.JavaRuntime$RequestRunnable.run(JavaRuntime.java:446)
    at com.google.tracing.TraceContext$TraceContextRunnable.runInContext(TraceContext.java:437)
    at com.google.tracing.TraceContext$TraceContextRunnable$1.run(TraceContext.java:444)
    at com.google.tracing.CurrentContext.runInContext(CurrentContext.java:188)
    at com.google.tracing.TraceContext$AbstractTraceContextCallback.runInInheritedContextNoUnref(TraceContext.java:308)
    at com.google.tracing.TraceContext$AbstractTraceContextCallback.runInInheritedContext(TraceContext.java:300)
    at com.google.tracing.TraceContext$TraceContextRunnable.run(TraceContext.java:441)
    at com.google.apphosting.runtime.ThreadGroupPool$PoolEntry.run(ThreadGroupPool.java:251)
    at java.lang.Thread.run(Thread.java:724)
Caused by: java.lang.ClassNotFoundException: com.googlecode.objectify.ObjectifyService
    at com.google.appengine.runtime.Request.process-6d2a94d1cdc4ec4b(Request.java)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:360)
    at com.appspot.darkening.server.UserContextListener.contextInitialized(UserContextListener.java:33)
    at org.mortbay.jetty.handler.ContextHandler.startContext(ContextHandler.java:548)
    at org.mortbay.jetty.servlet.Context.startContext(Context.java:136)
    at org.mortbay.jetty.webapp.WebAppContext.startContext(WebAppContext.java:1250)
    at org.mortbay.jetty.handler.ContextHandler.doStart(ContextHandler.java:517)
    at org.mortbay.jetty.webapp.WebAppContext.doStart(WebAppContext.java:467)
    at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:50)
    at com.google.tracing.TraceContext$TraceContextRunnable.runInContext(TraceContext.java:437)
    at com.google.tracing.TraceContext$TraceContextRunnable$1.run(TraceContext.java:444)
    at com.google.tracing.CurrentContext.runInContext(CurrentContext.java:188)
    at com.google.tracing.TraceContext$AbstractTraceContextCallback.runInInheritedContextNoUnref(TraceContext.java:308)
    at com.google.tracing.TraceContext$AbstractTraceContextCallback.runInInheritedContext(TraceContext.java:300)
    at com.google.tracing.TraceContext$TraceContextRunnable.run(TraceContext.java:441)
    ... 1 more

我的导入:

import com.appspot.darkening.model.User;
import com.googlecode.objectify.Objectify;
import com.googlecode.objectify.ObjectifyService;

它说我的 Usercontextlistener 中的第 33 行有问题:

public class UserContextListener implements ServletContextListener {
    private static final Logger log = Logger.getLogger(UserContextListener.class.getName());
    private Objectify ofy;

    @Override
    public void contextDestroyed(ServletContextEvent sce) {
        // TODO Auto-generated method stub
    }

    @Override

    public void contextInitialized(ServletContextEvent sce) {

     line 33->  Objectify ofy = ObjectifyService.begin(); <-line33
        ObjectifyService.register(User.class);
        User u1 = new User("123", "123", "Test-User", 1);
                //er wordt een dummy objecten aangemaakt
        Date date = new Date();
        User u = new User("admin", "admin", "Overseer", 5); 

        ofy.put(u);
        ofy.put(u1);

我已经按照下面的建议导入了正确的库,但这并不能解决我的问题。 我根本不明白我现在做错了什么。有人可以帮我解决可能出现的问题吗?如有任何帮助,我们将不胜感激。

最佳答案

您的项目中需要这些依赖项:

   <dependency>
        <groupId>com.googlecode.objectify</groupId>
        <artifactId>objectify</artifactId>
        <version>5.0</version>
    </dependency>

    <dependency>
        <groupId>com.google.guava</groupId>
        <artifactId>guava</artifactId>
        <version>18.0</version>
    </dependency>

关于java.lang.NoClassDefFoundError : com/googlecode/objectify/ObjectifyService,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21628560/

相关文章:

java - REST API 设计查询 2

java - java中字符串到字节,反之亦然

java - JERSEY 在 Google App Engine 中上传文件

python - 此处不允许映射值...在 foo.py 中

java - 使用对象 java.util.Date 时得到错误的星期几

java - hazelcast-kubernetes 网络发现 : How to use with Multiple Nodes

eclipse - eclipse 可以配置为自动修复丢失的导入吗?

java - 我可以强制控制台将价格和小费保持在同一条线上吗?

Java:同步标准输出和标准错误

google-app-engine - 是否可以在没有 Google Cloud SQL 的情况下在 App Engine/PHP 中使用数据库