0

这是我的问题的减少:

我有以下文件:src/main/resources/configs/config.properties
该文件有一个属性:uselive = true

我想从托管在 Cloudbees 平台上的 Java Web 应用程序访问此文件并阅读其内容。

为了读取这个文件,我应该使用什么访问路径?

4

2 回答 2

2

You can't rely on filesystem on RUN@Cloud. Filesystem is not persistent neither distributed, so as your application is (re)deployed it will get a fresh new node with empty filesystem, or if you scale-out on the cluster all nodes won't see consistent files.

We provide http://wiki.cloudbees.com/bin/view/RUN/Configuration+Parameters to handle application configuration. You also can put system properties configuration in http://wiki.cloudbees.com/bin/view/RUN/CloudBeesWebXml as well if you prefer this option

于 2012-09-18T09:15:14.740 回答
2

通常,您将使用类加载器访问部署在 WEB-INF 文件夹中的资源:

http://docs.oracle.com/javase/7/docs/api/java/lang/ClassLoader.html#getResourceAsStream(java.lang.String

所以像下面这样的东西会给你一个流:

getClassLoader().getResourceAsStream("configs/config.properties");
于 2012-09-19T02:08:04.577 回答