如何在Google App Engine中加载属性文件? [英] How to load properties file in Google App Engine?

查看:123
本文介绍了如何在Google App Engine中加载属性文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此,我正在尝试为我的项目添加一些功能,以允许我的部署工件中使用用户定义的属性 - 一个简单的键:value .properties文件。我将service.properties文件放置在

  war / WEB-INF / my-service.properties 

在我的ServiceImpl.java构造函数中,我有以下内容:

 字符串propertiesFileName =my-service.properties; 

URL propertyURL = ClassLoader.getSystemResource(propertiesFileName);
URL propertyURL2 = this.getClass()。getClassLoader()。getResource(propertiesFileName);
URL propertyURL3 = this.getClass()。getClassLoader()。getResource(WEB-INF /+ propertiesFileName);
URL propertyURL6 = this.getClass()。getClassLoader()。getResource(
E:/ Projects / eclipse-workspace / projectName / war / WEB-INF /+ propertiesFileName);

所有Property URL的实例均为null。我知道我错过了一些绝对明显的东西,但我需要第二双眼睛。

编辑:



啊,看起来我很困惑,因为默认GAE项目会创建日志记录。属性文件在/战争。从 Google App Engine文档



App Engine Java SDK在appengine-java-sdk / config / user /目录中包含一个模板logging.properties文件。要使用它,请将文件复制到您的WEB-INF / classes目录(或WAR中的其他地方),然后将系统属性java.util.logging.config.file复制到WEB-INF / classes / logging.properties(或无论您选择哪条路径,相对于应用程序根目录)。您可以在appengine-web.xml文件中设置系统属性,如下所示:

解决方案

尝试将service.properties放入WEB-INF / classes中。然后它应该可以通过以下方式访问:

  this.getClass()。getClassLoader()。getResourceAsStream(/ filename.properties ); 


So I'm trying to add some ability to my project to allow user-defined properties in my deployment artifact - a simple key:value .properties file. I place the service.properties file in

war/WEB-INF/my-service.properties 

And in my ServiceImpl.java constructor I have the following:

String propertiesFileName = "my-service.properties"; 

URL propertyURL = ClassLoader.getSystemResource(propertiesFileName);
URL propertyURL2 = this.getClass().getClassLoader().getResource(propertiesFileName);
URL propertyURL3 = this.getClass().getClassLoader().getResource( "WEB-INF/" + propertiesFileName);
URL propertyURL6 = this.getClass().getClassLoader().getResource(
       "E:/Projects/eclipse-workspace/projectName/war/WEB-INF/" + propertiesFileName);

All instances of Property URL are null. I know I'm missing something absolutely obvious, but I need a second pair of eyes. Regards.

EDIT:

Ah, it seems I was confused as the default GAE project creates a logging.properties file in /war. From the Google App Engine documentation:

The App Engine Java SDK includes a template logging.properties file, in the appengine-java-sdk/config/user/ directory. To use it, copy the file to your WEB-INF/classes directory (or elsewhere in the WAR), then the system property java.util.logging.config.file to "WEB-INF/classes/logging.properties" (or whichever path you choose, relative to the application root). You can set system properties in the appengine-web.xml file, as follows:

解决方案

Try putting the service.properties in WEB-INF/classes. Then it should be accessible just with :

this.getClass().getClassLoader().getResourceAsStream("/filename.properties");

这篇关于如何在Google App Engine中加载属性文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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