简体   繁体   English

将应用程序部署到GAE时,WAR文件中GCM的api.key文件应位于何处?

[英]Where should GCM's api.key file be located in the WAR file when deploying application to GAE?

I am attempting to get my .war file that was previously running on my machine locally with Tomcat 6 up on Google Apps. 我正在尝试获取以前在我的计算机上本地运行的.war文件,并在Google Apps上使用Tomcat 6。 I created the project in Eclipse and the file structure was a little bit different than Google's GCM Example . 我在Eclipse中创建了该项目,其文件结构与Google的GCM Example略有不同。 I think I finally have everything in order except for ONE last portion. 我想除了最后一个部分,我终于有了一切。 I don't know what directory the "api.key" belongs under. 我不知道“ api.key”属于哪个目录。 The stack trace in my logs on the Google Apps server is the following: 我在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)

You can view what Google says the directories should look like at this link . 您可以在此链接中查看Google所说的目录外观。 When I followed Google's GCM Demo (the first link up top) it placed the "api.key" file under the WEB-INF/classes directory. 当我关注Google的GCM演示(最上方的第一个链接)时,将“ api.key”文件放置在WEB-INF / classes目录下。 I try that in the new Google App Engine structure, and I get the error above. 我在新的Google App Engine结构中尝试了此操作,但出现了以上错误。 I feel like I'm really close as it's clear my servlet is TRYING to run, but it can't find this file. 我感觉我真的很接近,因为很明显我的servlet正在尝试运行,但是找不到该文件。 Does anyone know where to put it so it can find it and I can get this working? 有谁知道在哪里放置它可以找到它并且我可以正常工作?

Ok, I figured it out. 好的,我知道了。 In my ApiKeyInitializer.java class, I had this: 在我的ApiKeyInitializer.java类中,我有以下内容:

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

When in fact, it should have been this: 实际上,应该是这样的:

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

I followed these instructions for the build file. 我遵循了有关构建文件的这些说明 I noticed that it said All other files found in src/, such as the META-INF/ directory, are copied verbatim to war/WEB-INF/classes/ . 我注意到它说All other files found in src/, such as the META-INF/ directory, are copied verbatim to war/WEB-INF/classes/ This made me realize that I should put the api.key in my Eclipse src directory, so that when compiled it was placed properly in war/WEB-INF/classes. 这使我意识到我应该将api.key放在我的Eclipse src目录中,以便在编译时将其正确放置在war / WEB-INF / classes中。 In addition to that, the path had to be relative to the src directory, which is why I needed to do String PATH = "api.key" rather than String PATH = "/api.key" . 除此之外,该路径必须相对于src目录,这就是为什么我需要执行String PATH = "api.key"而不是String PATH = "/api.key"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM