Is it bad practice to include properties/configuaration files within jars?

前端 未结 11 1009
谎友^
谎友^ 2021-02-07 00:34

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

11条回答
  •  忘了有多久
    2021-02-07 01:15

    I think the answer depends on whether you think you need to version control for the configs. (They could be production configs or configs for regression testing ...)

    • If you don't need version control, then option D with an external property file that overrides a property file is a good one. Options B and C are more open to stuff-ups, but if you really cared you'd be using version control :-)
    • If you need version control, option A gives you more control, but if you have the possibility of multiple deployments you may also want/need to version control the configs for each deployment. An example is separate deployments to test and production platforms.

    Here's how we do this using Maven modules and Maven WAR file "overlays".

    1. We have multiple modules for the Java code components. These are JAR modules.
    2. We have "base webapp" module for the static content, JSPs and core configuration data (Spring wiring, default properties). This is a WAR module, so the result of building is a WAR that contains the above + all JAR files.
    3. Each distinct "site configuration" is a WAR module that contains site-specific overrides for properties, wiring files and content. The overriding is described using the Maven WAR "overlay" mechanism, and results in a new WAR being assembled from the "base" WAR and the overrides.

    All of this is checked into version control, and you need to do a Maven build and WAR deployment to make configuration changes.

提交回复
热议问题