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

时间:2014-02-07 13:04:55

标签: java eclipse google-app-engine objectify

我尝试在Appengine上运行我的Project,但是当我进入登录页面时,我得到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);

我已经导入了正确的库,如下所示,但它并没有解决我的问题。 我现在根本无法弄清楚我做错了什么。任何人都可以帮我解决问题所在吗?任何帮助表示赞赏。

6 个答案:

答案 0 :(得分:2)

您需要在项目中使用这些依赖项:

   <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>

答案 1 :(得分:1)

您需要将objectify-N.N.N.jarguava-N.N.N.jar添加到项目的WEB-INF\lib目录中。请参阅官方Objectify项目页面上的Setup Wiki。

答案 2 :(得分:0)

正确的objectify jar没有与您的部署一起打包。你需要找出原因,这取决于你如何进行部署(maven,ant,eclipse,intellij等)。这个问题没有足够的信息;您应该在查看打包和部署时查看代码。

答案 3 :(得分:0)

别忘了添加Romin提到的jar来为你的项目建立路径。

答案 4 :(得分:0)

我收到了以下错误。

Uncaught exception from servlet
java.lang.NoClassDefFoundError: com/google/appengine/api/datastore/AsyncDatastoreService
    at com.googlecode.objectify.ObjectifyService.<clinit>(ObjectifyService.java:18)
    at com.isyoudone.dbentity.ClientTokenItem.<clinit>(ClientTokenItem.java:24)
    at com.isyoudone.StoreClientServlet.doGet(StoreClientServlet.java:45)

与你的相似。当我上传时,本地和服务器上都伴随着这些警告。

Failed to read file: /base/data/home/apps/s~isyoudone/0.375907684014000310/WEB-INF/lib/appengine-jsr107cache-1.9.4.jar
java.util.zip.ZipException: error in opening zip file
    at java.util.zip.ZipFile.open(Native Method)
    at java.util.zip.ZipFile.<init>(ZipFile.java:228)
    at java.util.zip.ZipFile.<init>(ZipFile.java:157)
    at java.util.jar.JarFile.<init>(JarFile.java:153)

事实证明,尽管我使用的是maven,但我对将JAVA_HOME设置为正确的版本感到沮丧,并且更新了Eclipse以使用AppEngine插件。这已将特定版本的相关jar文件放在

<强> \ SRC \主\ web应用\ WEB-INF \ lib中

当我最终使用maven版本时,它使用的是这些文件的错误版本,而不是maven目标目录中的文件。删除上面目录中的所有内容,解决了问题。

答案 5 :(得分:0)

确认文件需要位于WEB-INF / lib目录中。当我将jar放在lib下面的“UserLibrary”目录中时,我收到了同样的错误。因此,请确保文件确实位于WEB-INF / lib的根级别,您应该很高兴。