创建GCM演示应用程序时出现Javac错误(Google App Engine Java / Windows 7)

时间:2013-06-03 11:44:16

标签: google-app-engine push-notification google-cloud-messaging javac api-key

我正在尝试按照“官方”教程(http://developer.android.com/google/gcm/demo.html)在Windows 7上创建适用于Android的GCM演示应用程序。

特别是,我正在尝试使用Java App Engine创建服务器,如上述教程中所述:

  

使用标准App Engine for Java设置服务器:

     
      
  1. 从SDK Manager中,安装Extras>适用于Android库的Google Cloud Messaging。这将创建一个gcm目录   YOUR_SDK_ROOT / extras / google /包含这些子目录:   gcm-client,gcm-server,samples / gcm-demo-client,   samples / gcm-demo-server和samples / gcm-demo-appengine。

  2.   
  3. 在文本编辑器中,编辑samples / gcm-demo-appengine / src / com / google / android / gcm / demo / server / ApiKeyInitializer.java   并使用上面获得的API密钥替换现有文本。

         

    注意:该类中设置的API密钥值将仅使用一次在App Engine上创建持久性实体。如果部署了   应用程序,您可以使用App Engine的数据存储查看器进行更改   后面。

  4.   
  5. 在shell窗口中,转到samples / gcm-demo-appengine目录。

  6.   
  7. 通过ant runserver启动开发App Engine服务器,使用-Dsdk.dir指示A​​pp Engine SDK的位置,使用-Dserver.host设置服务器的主机名或IP地址:

         

    $ ant -Dsdk.dir = / opt / google / appengine-java-sdk runserver -Dserver.host = 192.168.1.10   Buildfile:gcm-demo-appengine / build.xml

  8.   

我已按照这些步骤操作,并收到以下错误:

C:\Users\p\AppData\Local\Android\android-sdk\extras\google\gcm\samples\gcm-demo-appengine>ant -Dsdk.dir C:/Users/p/appengine-java-sdk-1.8.0 runserver -Dserver.host=192.168.44.1 Buildfile: gcm-demo-appengine/build.xml
Buildfile: C:\Users\p\AppData\Local\Android\android-sdk\extras\google\gcm\samples\gcm-demo-appengine\build.xml

init:

copyjars:

compile:
    [javac] Compiling 8 source files to C:\Users\p\AppData\Local\Android\android-sdk\extras\google\gcm\samples\gcm-demo-appengine\WebContent\WEB-INF\classes
    [javac] C:\Users\p\AppData\Local\Android\android-sdk\extras\google\gcm\samples\gcm-demo-appengine\src\com\google\android\gcm\demo\serer\ApiKeyInitializer.java:1: reached end of file while parsing
    [javac] AIzbSyBQdFestseFygh7Q22dxEfdsyc_k->
    [javac] ^
    [javac] 1 error

BUILD FAILED

“解析时到达文件末尾” - 据我所知,这个错误通常是由于缺少括号引起的 - 但是,我所做的就是在记事本中编辑ApiKeyInitializer.java文件输入API密钥;我没有触及任何代码!我试图在网上找到解决方案,但无济于事。

有谁知道可能导致此问题的原因以及我如何解决这个问题?非常感谢提前!

1 个答案:

答案 0 :(得分:1)

我检查了ApiKeyInitializer.java文件(我在计算机上本地使用它)。 它看起来像一个有效的java类:

/*
 * Copyright 2012 Google Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.google.android.gcm.demo.server;

import com.google.appengine.api.datastore.DatastoreService;
import com.google.appengine.api.datastore.DatastoreServiceFactory;
import com.google.appengine.api.datastore.Entity;
import com.google.appengine.api.datastore.EntityNotFoundException;
import com.google.appengine.api.datastore.Key;
import com.google.appengine.api.datastore.KeyFactory;

import java.util.logging.Logger;

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;

/**
 * Context initializer that loads the API key from the App Engine datastore.
 */
public class ApiKeyInitializer implements ServletContextListener {

  static final String ATTRIBUTE_ACCESS_KEY = "apiKey";

  private static final String ENTITY_KIND = "Settings";
  private static final String ENTITY_KEY = "MyKey";
  private static final String ACCESS_KEY_FIELD = "ApiKey";

  private final Logger logger = Logger.getLogger(getClass().getName());

  public void contextInitialized(ServletContextEvent event) {
    DatastoreService datastore = DatastoreServiceFactory.getDatastoreService();
    Key key = KeyFactory.createKey(ENTITY_KIND, ENTITY_KEY);

    Entity entity;
    try {
      entity = datastore.get(key);
    } catch (EntityNotFoundException e) {
      entity = new Entity(key);
      // NOTE: it's not possible to change entities in the local server, so
      // it will be necessary to hardcode the API key below if you are running
      // it locally.
      entity.setProperty(ACCESS_KEY_FIELD,
          "replace_this_text_by_your_Simple_API_Access_key");
      datastore.put(entity);
      logger.severe("Created fake key. Please go to App Engine admin "
          + "console, change its value to your API Key (the entity "
          + "type is '" + ENTITY_KIND + "' and its field to be changed is '"
          + ACCESS_KEY_FIELD + "'), then restart the server!");
    }
    String accessKey = (String) entity.getProperty(ACCESS_KEY_FIELD);
    event.getServletContext().setAttribute(ATTRIBUTE_ACCESS_KEY, accessKey);
  }

  public void contextDestroyed(ServletContextEvent event) {
  }

}

也许您以某种方式删除了该文件的内容。