在jars中包含properties / configuaration文件是不好的做法吗? [英] Is it bad practice to include properties/configuaration files within jars?

查看:333
本文介绍了在jars中包含properties / configuaration文件是不好的做法吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

例如:



MyApp是一个包含属性文件(server.properties)的网络应用程序,用于描述应用程序的配置数据(例如服务器名称)。在开发阶段,server.properties位于其自己的IDE项目文件夹(它的逻辑地方)。



现在是部署MyApp的时候了。 IDE使得对类文件以及支持配置文件进行jar操作非常简单。现在我们只是把Jar放在适当的web容器中,走开去。



一个星期后... MyApp使用的服务器配置数据需要改变。这更有意义吗?



A。在IDE中修改server.properties文件,并生成一个全新的jar文件。重新部署。 (这意味着为简单的配置更改弹回应用程序)。



B。破解打开已部署的Jar并修改server.properties文件? (可能必须调用一个刷新功能在MyApp如果server.properties被缓存...但不应该需要一个完整的应用程序反弹。还需要记住修改源server.properties以及所以未来的部署不恢复server.properties到旧的服务器名称)。



C。首先将server.properties设置为jar文件的外部。非常类似于B的过程,与保持配置数据外部到jar(引入开发和生产部署之间的不同路径)的微小差别



D。其他:



谢谢!

解决方案



尝试从.jar外部加载属性文件,然后如果失败,则加载内置到jar中的属性。



这样,你可以通过每个构建推出一个现成的配置(也可以减少部署的复杂性,如果只有一个文件),同时使重写配置成为可能和相当简单。

For example:

MyApp is a web app that contains a properties file (server.properties) that describes config data (e.g. server names) for the app. In the development phase, server.properties is located in its own IDE project folder (a logical spot for it).

Now it's time to deploy MyApp. The IDE makes it quite trivial to jar up the class files as well as the supporting config files. Now we just drop the Jar in the appropriate web container and away we go....

A week later... the server config data that MyApp uses needs to change. Which makes more sense?

A. Modify the server.properties file back in IDE land and generate a completely new jar file. Redeploy. (which means bouncing the app for a simple configuration change).

B. Crack open the already deployed Jar and modify the server.properties file? (may have to call a refresh function in MyApp if server.properties is cached... but should not require a full app bounce. Also need to remember to modify source server.properties as well so future deploys don't revert server.properties to the old server names).

C. Make server.properties external to the jar file in the first place. Very similar to B's process, with the minor difference of keeping config data external to the jar (introduces different paths between development and production deploys)

D. Other:

Thanks!

解决方案

I'd go with D.

Try to load the properties files from outside the .jar then, if that fails, load the properties built into the jar.

This lets you push out a "ready made" configuration with each build (also reduces the complexity of a deployment, if by just one file), while also making overriding configurations possible and reasonably simple.

这篇关于在jars中包含properties / configuaration文件是不好的做法吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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