【问题标题】:Manage patch info on WAR管理关于 WAR 的补丁信息
【发布时间】:2014-07-19 01:17:48
【问题描述】:

管理 j2ee WAR 文件上的补丁版本信息的最佳/正确方法是什么
我想在 WAR 文件中维护补丁信息,以便在应用程序运行后出于维护目的,此信息可以显示在应用程序中。
正在考虑几种可能的方法:

  1. 使用 DB 表——(我想避免这种方法)
    • 缺点
      • 将 WAR 版本耦合到数据库
      • 带有补丁的数据库脚本的额外开销。
  2. 将内部 XML 文件添加到资源中,然后读取和分析/解析它
    • 缺点
      • 访问 XML 的问题(物理路径问题?)
  3. 将补丁信息添加到 MANFIEST 文件
    • 缺点
      • 无法在应用中显示?

我想知道是否有更多方法以及最适合这种要求的方法。
谢谢

【问题讨论】:

  • 你想用 maven 做吗?
  • 更新版本的过程将手动完成。 (爆炸战争和更新文件)
  • 关于 1,查看 SQLite 并将文件嵌入到 WAR 中。它本质上是 2,带有更多类似 DB 的东西。你可以通过getResourceAsStream()来避免路径问题。
  • 我会选择第二个选项。打开存储在classes目录下的XML文件很方便。
  • 修补 Web 应用程序并不是一个好习惯,因为它很少可重复。您最好构建并发布带有新版本的全新 WAR 文件。

标签: java jakarta-ee manifest war


【解决方案1】:

考虑到您的问题,您可以通过多种方式存储您的版本:

1.DB表

pro : ?
cons: infra dependant, need to update db, can be desynchronized
conclusion :please avoid that, it is dependant of your infrastructure.

2。属性文件:最佳选择!

pro: simple to integrate, ressource is localized by java.util.Properties, implement in 15 min.
cons: ? 
conclusion: Simple and easy; the best choice for me. Take a look to the code 

3。 Manifest

pro: may work
cons: bad practice to use a defined component for another purpose, bad architecture practice
conclusion: Avoid this solution, it's a bad architecture practice.

WINNER:属性代码示例,不到 15 分钟即可完成测试。

public static Properties loadProperties() {
        String resourceName = "version.properties";

        Properties prop = new Properties();
        try {
            prop.load(DBTools.class.getResourceAsStream(resourceName));
            logger.trace(String.format("config file %s loadded with success !", resourceName));
        } catch (IOException e) {
            logger.error(String.format("config file %s is not loaded!", resourceName));
        }
        return prop;
    }



  version.properties File 
    APP-VERSION=1.12.4-REV2345-NIGHT

当您想在您的应用中检索 app_version 时,只需执行以下操作:

property.getProperty("APP-VERSION");

【讨论】:

  • 用户想要更改日志,而不仅仅是版本。对于版本,他可以使用 MANIFEST 文件。看我的回答
  • 你说得对,我们可以这样做。这只是建筑/设计哲学的问题。
【解决方案2】:

使用 manifest.mf,每次构建时都必须重新生成该文件,包括以下条目:

Implementation-Title: The value is a string that defines the title of the extension implementation.
Implementation-Version: The value is a string that defines the version of the extension implementation.
Implementation-Vendor: The value is a string that defines the organization that maintains the extension implementation.
Implementation-Vendor-Id: The value is a string id that uniquely defines the organization that maintains the  extension implementation.
Implementation-URL: This attribute defines the URL from which the extension implementation can be downloaded from.
Specification-Title: The value is a string that defines the title of the extension specification.
Specification-Version: The value is a string that defines the version of the extension specification.
Specification-Vendor: The value is a string that defines the organization that maintains the extension specification.

这里是关于如何从 servlet How to read MANIFEST.MF inside WAR application? 读取它的讨论

【讨论】:

    【解决方案3】:

    不要为此使用 MANIFEST。创建您自己的变更日志文件格式,将其捆绑在您的 WAR 文件中,位于您的应用程序已知的位置,然后在您的应用程序中创建一个功能来显示它。 MANIFEST 不是为存储变更日志而设计的,从长远来看,如果你这样做只会给你带来问题。我建议您添加一个属性,告诉您该版本的变更日志所在的位置。例如:

    --- MANIFEST ----
    Application-Version: 1.2.5
    My-App-Changelog: /WEB-INF/changelogs/version-1.2.5.xml
    -----------------
    

    根据您使用的应用程序服务器或 Web 容器,您可能能够创建一个扩展程序或另一个应用程序= 来检查所有已部署的 WAR 并显示此信息。您将需要使用供应商特定的 API。

    每次发布​​新版本时,该存档都会包含所有版本的版本号和变更日志,便于快速跟踪变更。

    【讨论】:

      猜你喜欢
      • 2018-04-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-07-08
      • 2011-03-04
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多