在j2ee WAR文件上管理补丁版本信息的最佳/正确方法是什么?
我想在WAR文件中维护补丁信息,因此一旦运行它以进行维护,这些信息就会显示在应用程序内部。
想到几种可能的方法:
我想知道是否有更多的方法和最适合这种要求的方法。
谢谢
答案 0 :(得分:2)
考虑到您的问题,您可以通过多种方式存储您的版本:
pro : ? cons: infra dependant, need to update db, can be desynchronized conclusion :please avoid that, it is dependant of your infrastructure.
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
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.
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");
答案 1 :(得分:1)
使用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?
中读取它的讨论答案 2 :(得分:1)
不要使用MANIFEST。创建您自己的更改日志文件格式,将其捆绑在WAR文件中的应用程序已知的位置,并在您的应用程序中创建一个功能来显示它。 MANIFEST不是为存储更改日志而设计的,从长远来看,如果你这样做只会给你带来麻烦。我建议你添加一个属性,告诉你该版本的更改日志所在的位置。例如:
--- MANIFEST ----
Application-Version: 1.2.5
My-App-Changelog: /WEB-INF/changelogs/version-1.2.5.xml
-----------------
根据您使用的应用程序服务器或Web容器,您可以创建扩展或其他app =内省所有已部署的WAR并显示此信息。您将需要使用特定于供应商的API。
每次发布新版本时,该存档都将包含所有版本的版本号和更改日志,这有助于快速跟踪更改。