简体   繁体   English

用于管理glassfish / tomcat / etc中的.properties文件的优雅解决方案

[英]Elegant solution for managing .properties files in glassfish/tomcat/etc

Does anybody have a good solution for managing .properties files in a web application? 有没有人有一个很好的解决方案来管理Web应用程序中的.properties文件? Currently I have to pull apart my .war file before deploying, change the entries in my .properties file, and then redeploy to change settings. 目前,我必须在部署之前拆分我的.war文件,更改.properties文件中的条目,然后重新部署以更改设置。

Alternatively I can ssh into the server, change the .properties file in the deploy directory and restart the application. 或者,我可以ssh到服务器,更改deploy目录中的.properties文件并重新启动应用程序。

A coworker has a rather elegant solution of using the GUI for setting JNDI properties in your Tomcat/Glassfish instance and reading those instead of a .properties file. 同事有一个相当优雅的解决方案,使用GUI在Tomcat / Glassfish实例中设置JNDI属性并读取它们而不是.properties文件。 The problem here is that when handing off the application to our operations teams they need to know which properties to add to JNDI. 这里的问题是,当将应用程序交给我们的运营团队时,他们需要知道要添加到JNDI的属性。

Has anybody found a great way to deal with this issue? 有人找到了处理这个问题的好方法吗?

One simple option is to store the properties file external to the WAR file / webapp, so that 1) they are not changed on each deployment and 2) do not need to be edited. 一个简单的选项是将属性文件存储在WAR文件/ webapp外部,以便1)在每次部署时不更改它们,2)不需要编辑。 You would simply need to adjust the logic in your webapp having to do with where the files are found. 您只需将需要调整的逻辑在你的web应用具有了文件的发现这样做。

Another option, only slightly less simple, is to use filtering during the build process so that the WAR file is build to contain properties file that are customized to the target environment. 另一个选项,只是稍微简单一点,就是在构建过程中使用过滤,以便构建WAR文件以包含为目标环境定制的属性文件。 Both Ant and Maven support a very easy mechanism for using tokens and filter files to filter certain resources. AntMaven都支持使用令牌和过滤文件来过滤某些资源的非常简单的机制。

如果您可以以xml格式存储属性(我相信jdk支持),那么有一堆开源库可以为此生成crud ui ....如果不是我找到的最接近的是PropertySet @ 链接文本

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

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