简体   繁体   English

如果属性文件中的值可能会更改怎么办?

[英]What if values in properties files are subject to change?

I have read that files within a jar file are not supposed to be modified, and I think that explains why getting an outputStream is not as simple as getting an inputStream calling getClass().getResourceAsStream() to read a file. 我已经读过,不应修改jar文件中的文件,并且我认为这解释了为什么获取outputStream并不像获取调用getClass().getResourceAsStream()inputStream那样简单。 When using properties files values are going to be retrieved during execution, but what if those values are subject to change? 使用属性文件时,将在执行过程中检索值,但是如果这些值可能会发生变化怎么办? It would be tedious to recompile the program. 重新编译程序将很繁琐。

In my case those values are IP address, username and a path to an external file. 在我的情况下,这些值是IP地址,用户名和外部文件的路径。 So I guess I could not move the external file even by accident because my properties file in the jar have a different path to that file. 因此,我想即使是偶然也无法移动外部文件,因为jar中的属性文件具有与该文件不同的路径。 Is this the way is supposed to be or is there a more flexible way that I am not aware of? 这是应该的方式还是我不知道的更灵活的方式?

Usually property files are located outside of jar somewhere on production system's classpath. 通常,属性文件位于jar之外,位于生产系统的类路径上的某个位置。 Values are usually changed once in a while via provisioning scripts / manually and then only application restart is required, not a re-compile. 通常会通过配置脚本/手动偶尔更改值,然后仅需要重新启动应用程序,而无需重新编译。

So, to sum it up, I'd suggest not having properties file inside the jar. 因此,总而言之,我建议jar中不要包含属性文件。

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

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