Java 属性文件的良好存储库组织实践
我维护一个多平台开发框架,尝试根据通过各种方式推断的某些系统和环境信息来配置环境变量。一旦推断出这些变量,我会将它们存储在 Java 属性文件中以供以后使用。该文件也可以由我的框架的用户(开发人员)编辑。
我有一个名为 Env
的类来管理此属性文件,它位于名为 org.myproject.config
的包中。我当前将默认属性文件存储在 src/org/myproject/config
中。我想知道,在我的项目的这个目录下存储配置类型文件是一个好习惯吗?不知道该去哪里。任何意见都会受到赞赏。
-tjw
I maintain a multi-platform development framework that attempts to configure environment variables based on certain system and environment information that is inferred via various means. Once I infer these variables, I store them in a Java properties file for later use. This file could also be edited by the user of my framework (a developer).
I have a class called Env
that manages this properties file, and it's in a package called org.myproject.config
. I'm currently storing the default properties file in src/org/myproject/config
. I'm wondering, is it good practice to store a config-type file under this directory of my project? Not sure where to go with this. Any input is appreciated.
-tjw
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您应该使用 Java Preferences API,如果您希望保持平台中立。一旦指定了文件路径,您就可以对应用程序运行的环境做出很多假设。
You should use the Java Preferences API if you wish to maintain platform neutrality. Once you specify a file path, you make a lot of assumptions about the environment your application is running on.
根据我们的经验,特定于环境的信息不应存储在存储库中。有人错误地更新了文件,当他提交时,其他用户/环境就会受到影响。我们在每个环境中保持环境配置独立且本地化。在我们的例子中,环境变量存储在数据库表中,属性文件中唯一的环境信息是创建到环境变量位置的 JDBC 连接所需的最少字段。环境更新通过 IT 变更请求或通过软件升级完成。
From what we experienced, environment specific information should not be stored on a repository. Someone updates by mistake an file and when he commits other users/environments are affected. We keep environment configuration separate and local on each environment. In our case the environment variables are stored in database tables, and the only environment information we have in property files is the minimum required fields to create a JDBC connection to the location of the environment variables. updates to environments pass through a IT change request or are done via an software upgrade.