物化OfyService NoClassDefFoundError的App Engine的端点 [英] Objectify OfyService NoClassDefFoundError for app engine endpoint
问题描述
我的Android-的AppEngine端点项目设置完全由机器人工作室。因此,我不惹周围的任何东西:我只是让Android的工作室我的AppEngine模块添加到我的Android项目。现在,我得到一个 java.lang.NoClassDefFoundError的
。我一定要在设置的gradle出头或配置在Android Studio中出头摆脱这种错误的?基本上,当我尝试测试我的应用程序我得到的异常。
My android-appengine-endpoint project is setup entirely by android studio. Therefore I don't mess around with anything: I just let android studio add my AppEngine module to my android project. Now I am getting a java.lang.NoClassDefFoundError
. Do I have to set somethings in gradle or configure somethings in android studio to get rid of this error? Basically when I try to test my app I get the exception.
code:
注意:而不是调用的 OFY
我的端点类里面,userDAO的是一个地方,所有的 OFY
数据访问调用的。您可以比较我的code到<一个href=\"http://rominirani.com/2014/08/26/gradle-tutorial-part-9-cloud-endpoints-persistence-android-studio/\"相对=nofollow>本教程
Note: Instead of calling ofy
inside my endpoint class, UserDao is a place where all the ofy
data access calls are made. You can compare my code to this tutorial
public class UserDao extends OfyService {
public static void persist(User user) {
ofy().save().entities(user).now();
}
public static User getById(long id) {
return ofy().load().type(User.class).id(id).now();
}
public static List<User> getByTwitterId(Long twitterId) {
return ofy().load().type(User.class).filter("twitterId", twitterId).list();
}
}
public class OfyService {
public OfyService() {}
static {
ObjectifyService.register(User.class);
ObjectifyService.register(Food.class);
ObjectifyService.register(Pet.class);
}
public static Objectify ofy() { return ObjectifyService.ofy(); }
public static ObjectifyFactory factory() {
return ObjectifyService.factory();
}
}
从App Engine的控制台中看到的实际的错误:
The actual error as seen from the App Engine Console:
com.google.api.server.spi.SystemService invokeServiceMethod: exception occurred while calling backed method
java.lang.NoClassDefFoundError: Could not initialize class com.mycompany.server.data.dao.UserDao
at com.mycompany.server.utils.Authenticator.verifyAccount(Authenticator.java:22)
at com.mycompany.server.endpoint.server.getFood(server.java:105)
at sun.reflect.GeneratedMethodAccessor22.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:44)
at com.google.api.server.spi.SystemService.invokeServiceMethod(SystemService.java:359)
at com.google.api.server.spi.SystemServiceServlet.execute(SystemServiceServlet.java:160)
at com.google.api.server.spi.SystemServiceServlet.doPost(SystemServiceServlet.java:118)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
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.googlecode.objectify.ObjectifyFilter.doFilter(ObjectifyFilter.java:48)
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
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 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.HttpConnection.handle(HttpConnection.java:404)
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:230)
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 java.lang.Thread.run(Thread.java:745)
每一个岗位我在这里看到的似乎是在谈论 WEB-INF \\ lib目录
。那么Android的工作室并没有创造任何lib目录下我的WEB-INF中。因此,无论Android的Studio和App Engine的是来自谷歌。因此,我在这里丧命。
Every post I see here seem to be talking about WEB-INF\lib
. Well Android Studio has not created any lib directory inside my WEB-INF. So both Android Studio and App Engine are from Google. Therefore I am at a lost there.
我的的webapp / WEB-INF
中有只有三个文件:
My webapp/WEB-INF
has only three files in it:
-
的web.xml
-
logging.properties
-
的AppEngine-web.xml中
web.xml
logging.properties
appengine-web.xml
下面是我的情况下,依赖的图像可以帮助:
Here is an image of my dependencies in case it helps:
推荐答案
由于您使用云端点,做到这一点:
Since you are using Cloud Endpoint, do this:
- 在你的端点类,创建一个构造。
- 在构造函数中,调用
新OfyService()
。
- In your Endpoint class, create a constructor.
- In the constructor, call
new OfyService()
.
这可能工作的原因是,你会加载所有的客观化相关类的方式方法需要(客户端进行第一次调用之前即方法)来使用它们。现在你所加载它们,你需要他们权利之前。而在App-Engine类加载器的延迟可能是什么杀了你。可悲的是,你正在使用的结构非常受欢迎,所以大多数人用这种方式:,但也不能保证它会一直工作。这是一个竞争条件的事情。应用引擎可以加载类很慢。幸运(或者不吉利)你,你及早发现问题。人们应该给你一些upvotes为您的痛苦。)
The reason this may work is that you will have loaded all your objectify related classes way way before you need to use them (i.e. way before a client makes a first call). Right now you are loading them right before you need them . And delays in the App-Engine class loader may be what's killing you. The sad thing is, the structure you are using is very popular and so most people use it that way: and yet there is no guarantee that it will always work. It's a race condition thing. App-engine can be very slow to load classes. Lucky (or unlucky) for you, you find the problem early. People should give you some upvotes for your pains :).
这篇关于物化OfyService NoClassDefFoundError的App Engine的端点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!