Google Cloud Endpoints不了解Objectify 4 Transaction中的Work类,从而导致ClassNotFoundException [英] Google Cloud Endpoints doesn't know about the Work class from Objectify 4 Transaction, causing ClassNotFoundException

查看:85
本文介绍了Google Cloud Endpoints不了解Objectify 4 Transaction中的Work类,从而导致ClassNotFoundException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个非常简单的Objectify/Endpoints类.

I created a very simple Objectify/Endpoints class.

import static mypackage.OfyService.ofy;

import com.google.api.server.spi.config.Api;
import com.google.api.server.spi.config.ApiMethod;
import com.googlecode.objectify.Work;

@Api(name = "testapi", version = "1")
public class TestEndpoint {

    @ApiMethod(name = "test.insert")
    public TestEntity insert(final TestEntity test) {
        test.setName("test");
        return ofy().transact(new Work<TestEntity>() {      
            public TestEntity run() {
                ofy().save().entities(test).now();
                return test;
            }
        });
    }

}

TestEntity很简单(为简洁起见,不包括getters和setters):

The TestEntity is trivial (getters & setters excluded for brevity):

@Entity
public class TestEntity {

    @Id long id;
    String name;
}

并且我使用 http://code.google上的OfyService模式.com/p/objectify-appengine/wiki/BestPractices#Use_Your_Own_Service

但是,当我尝试生成Endpoints库时,会收到ClassNotFoundException for Work.完整的堆栈跟踪如下:

However, when I try to generate the Endpoints library, I get a ClassNotFoundException for Work. Full stacktrace follows:

java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at com.google.gdt.eclipse.appengine.swarm.wizards.helpers.SwarmApiCreator.createSwarmApi(SwarmApiCreator.java:97)
at com.google.gdt.eclipse.appengine.swarm.wizards.helpers.SwarmServiceCreator.create(SwarmServiceCreator.java:196)
at com.google.gdt.eclipse.appengine.swarm.wizards.HandleGaeProjectChange.gaeProjectRebuilt(HandleGaeProjectChange.java:64)
at com.google.appengine.eclipse.core.properties.ui.GaeProjectChangeNotifier.build(GaeProjectChangeNotifier.java:77)
at org.eclipse.core.internal.events.BuildManager$2.run(BuildManager.java:728)
at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:199)
at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:239)
at org.eclipse.core.internal.events.BuildManager$1.run(BuildManager.java:292)
at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:295)
at org.eclipse.core.internal.events.BuildManager.basicBuildLoop(BuildManager.java:351)
at org.eclipse.core.internal.events.BuildManager.build(BuildManager.java:374)
at org.eclipse.core.internal.events.AutoBuildJob.doBuild(AutoBuildJob.java:143)
at org.eclipse.core.internal.events.AutoBuildJob.run(AutoBuildJob.java:241)
at org.eclipse.core.internal.jobs.Worker.run(Worker.java:53)
Caused by: java.lang.NoClassDefFoundError: com/googlecode/objectify/Work
    at java.lang.Class.getDeclaredMethods0(Native Method)
    at java.lang.Class.privateGetDeclaredMethods(Class.java:2427)
    at java.lang.Class.getDeclaredMethods(Class.java:1791)
    at com.google.api.server.spi.MethodHierarchyReader.addServiceMethods(MethodHierarchyReader.java:174)
    at com.google.api.server.spi.MethodHierarchyReader.readMethodHierarchyIfNecessary(MethodHierarchyReader.java:44)
    at com.google.api.server.spi.MethodHierarchyReader.getEndpointOverrides(MethodHierarchyReader.java:99)
    at com.google.api.server.spi.config.annotationreader.ApiConfigAnnotationReader.readApiMethods(ApiConfigAnnotationReader.java:184)
    at com.google.api.server.spi.config.annotationreader.ApiConfigAnnotationReader.readEndpoint(ApiConfigAnnotationReader.java:82)
    at com.google.api.server.spi.tools.AnnotationApiConfigGenerator.generateForService(AnnotationApiConfigGenerator.java:242)
    at com.google.api.server.spi.tools.AnnotationApiConfigGenerator.generateConfigObjects(AnnotationApiConfigGenerator.java:227)
    at com.google.api.server.spi.tools.AnnotationApiConfigGenerator.generateConfig(AnnotationApiConfigGenerator.java:176)
    ... 20 more

Caused by: java.lang.ClassNotFoundException: com.googlecode.objectify.Work
    at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
    ... 31 more

我在Endpoint类(例如Ref等)中包含的其他Objectify类没有类似的问题,并且我设置了包含Objectify 4.0b1库的Eclipse(4.2)项目.

I don't have similar problems with other Objectify classes I include in Endpoint classes (eg Ref, etc), and I have Eclipse (4.2) project set up to include the Objectify 4.0b1 library.

如果我将Endpoints类更改为使用VoidWork,则会收到完全相同的错误:

I get exactly the same error if I change the Endpoints class to use VoidWork:

@Api(name = "testapi", version = "1")
public class TestEndpoint {

  @ApiMethod(name = "test.insert")
  public TestEntity insert(TestEntity test) {
    final TestEntity newTest = new TestEntity();
    newTest.setName(test.getName());
    ofy().transact(new VoidWork() {

            public void vrun() {
                ofy().save().entities(newTest).now();
            }
        });
    return newTest;
  }

}

推荐答案

可以找到详细信息

Details can be found here for the maven setup. If you just want to get up and running fast, go [here](http://repo1.maven.org/maven2/com/googlecode/objectify/objectify/] and click on the latest version of Objectify (currently 4.0rc2/), then download the objectify-*version*.jarfile.

在Eclipse中:将objectify.jar以及 guava.jar 添加到[Project]/war/WEB-INF/lib.右键单击您的项目.转到属性-> Java构建路径->库.单击添加罐子…",导航到上述/lib文件夹,单击确定(对每个罐子都执行一次).

In Eclipse: add the objectify.jar as well as guava.jar to [Project]/war/WEB-INF/lib. Right click on your project. Go to Properties -> Java Build Path -> Libraries. Click "Add Jars…", navigate to the aforementioned /lib folder, click OK (do this once for each jar).

这篇关于Google Cloud Endpoints不了解Objectify 4 Transaction中的Work类,从而导致ClassNotFoundException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆