【问题标题】:Where should GCM's api.key file be located in the WAR file when deploying application to GAE?将应用程序部署到 GAE 时,GCM 的 api.key 文件应该位于 WAR 文件的哪个位置?
【发布时间】:2012-07-10 06:30:57
【问题描述】:

我正在尝试获取以前在我的机器上本地运行的 .war 文件,该文件使用 Google Apps 上的 Tomcat 6。我在 Eclipse 中创建了项目,文件结构与Google's GCM Example 有点不同。我想我终于把所有东西都整理好了,除了最后一部分。我不知道“api.key”属于哪个目录。我在 Google Apps 服务器上的日志中的堆栈跟踪如下:

Failed startup of context com.google.apphosting.utils.jetty.RuntimeAppEngineWebAppContext@1ef3ccd{/,/base/data/home/apps/s~[app-name]/1.360213803566389174}
java.lang.IllegalStateException: Could not find file /api.key on web resources)
    at [package-name].ApiKeyInitializer.getKey(ApiKeyInitializer.java:56)
    at [package-name].ApiKeyInitializer.contextInitialized(ApiKeyInitializer.java:45)
    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)

您可以在this link 上查看 Google 所说的目录应该是什么样子。当我关注 Google 的 GCM Demo(顶部的第一个链接)时,它将“api.key”文件放在 WEB-INF/classes 目录下。我在新的 Google App Engine 结构中尝试了这个,我得到了上面的错误。我觉得我真的很接近,因为很明显我的 servlet 正在尝试运行,但它找不到这个文件。有谁知道把它放在哪里以便它可以找到它并且我可以让它工作?

【问题讨论】:

  • 所以我才意识到,当我将文件放入 WEB-INF 中的 classes 文件夹时,它似乎在每次重建时都会被删除。 classes 目录在 Eclipse 中实际上是不可见的,这可能就是原因。我一直在手动通过 Windows 资源管理器将其放入...
  • 在关注this page: 之后我仍然无法得到它。我有一个构建脚本,将 api.key 放在 war/WEB-INF/classes 目录中,但是一旦在服务器上,我仍然会收到错误。

标签: java android google-app-engine war google-cloud-messaging


【解决方案1】:

好的,我想通了。在我的 ApiKeyInitializer.java 类中,我有这个:

private static final String PATH = "/api.key";

事实上,它应该是这样的:

private static final String PATH = "api.key";

我关注these instructions 获取构建文件。我注意到上面写着All other files found in src/, such as the META-INF/ directory, are copied verbatim to war/WEB-INF/classes/。这让我意识到我应该将 api.key 放在我的 Eclipse src 目录中,以便在编译时将其正确放置在 war/WEB-INF/classes 中。除此之外,路径必须相对于 src 目录,这就是为什么我需要使用String PATH = "api.key" 而不是String PATH = "/api.key"

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-03-18
    • 2019-08-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-11-17
    • 1970-01-01
    相关资源
    最近更新 更多