我正在尝试将数据从AppEngine插入Google数据存储区,但出现错误:

java.lang.IllegalArgumentException: A project ID is required for this service but could not be determined from the builder or the environment.  Please set a project ID using the builder.
    at com.google.common.base.Preconditions.checkArgument(Preconditions.java:92)
    at com.google.cloud.ServiceOptions.<init>(ServiceOptions.java:324)
    at com.google.cloud.datastore.DatastoreOptions.<init>(DatastoreOptions.java:85)
    at com.google.cloud.datastore.DatastoreOptions.<init>(DatastoreOptions.java:32)
    at com.google.cloud.datastore.DatastoreOptions$Builder.build(DatastoreOptions.java:75)
    at com.google.cloud.datastore.DatastoreOptions.defaultInstance(DatastoreOptions.java:123)

这是我的代码:
Datastore datastore = DatastoreOptions.defaultInstance().service();
             KeyFactory keyFactory = datastore.newKeyFactory().kind("keyKind");
             Key key = keyFactory.newKey("keyName");
             Entity entity = Entity.builder(key)
                 .set("name", "John Doe")
                 .set("age", 30)
                 .set("access_time", DateTime.now())
                 .build();
             datastore.put(entity);

如何解决此错误?

最佳答案

您正在运行AE standard还是AE Flexible

确保您的类路径(WEB-INF/lib目录)中有App Engine api jar

10-06 08:43