如何使用 Maven 将属性添加到 java Manifest
我从 Java 8 迁移到 Java 11,从 Ant 项目迁移到 Maven 项目,清单丢失了项目版本和构建日期信息。
我使用以下代码打印了 Manifest 的所有主要属性:
manifest = new Manifest(new URL(manifestPath).openStream());
Attributes attr = manifest.getMainAttributes();
// Enumerate each attribute
for (Iterator it=attr.keySet().iterator(); it.hasNext(); ) {
// Get attribute name
Attributes.Name attrName = (Attributes.Name)it.next();
String attrValue = attr.getValue(attrName);
AppLogger.getInstance().Log(attrName + ": " + attrValue);
}
这是我得到的所有属性名称: Main-Class、Class-Path、Build-Jdk、Built-By、Created-By、Manifest-Version、jar
没有项目版本或构建日期。
我应该在 POM 文件中进行哪些更改才能添加此信息?
I migrated from Java 8 to Java 11 and from Ant project to Maven project, the manifest lost the Project version and build date information.
I printed all Main attributes of Manifest using the following code:
manifest = new Manifest(new URL(manifestPath).openStream());
Attributes attr = manifest.getMainAttributes();
// Enumerate each attribute
for (Iterator it=attr.keySet().iterator(); it.hasNext(); ) {
// Get attribute name
Attributes.Name attrName = (Attributes.Name)it.next();
String attrValue = attr.getValue(attrName);
AppLogger.getInstance().Log(attrName + ": " + attrValue);
}
Here is all the attributes names that I get:
Main-Class, Class-Path, Build-Jdk, Built-By, Created-By, Manifest-Version, jar
There is no project version or build date.
What change should I do in my POM file, to add this information?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以在 pom.xml 中执行以下操作:
参考资料: https ://andresalmiray.com/customize-jar-manifest-entries-with-maven-gradle/,https://maven.apache.org/plugins/maven- jar-plugin/examples/manifest-customization.html
You can do something like this in your pom.xml:
References: https://andresalmiray.com/customize-jar-manifest-entries-with-maven-gradle/, https://maven.apache.org/plugins/maven-jar-plugin/examples/manifest-customization.html