public class JarVersionUtil extends Object
| 构造器和说明 |
|---|
JarVersionUtil() |
| 限定符和类型 | 方法和说明 |
|---|---|
static String |
getJarVersion(Class<?> clazz)
获取指定类所在 JAR 包中的 Implementation-Version 版本号。
|
static String |
getVersionFromPackage(Class<?> clazz)
通过指定类对应的 Package 对象获取其实现版本(Implementation-Version)。
|
static String |
getVersionFromPomProperties(Class<?> clazz,
String groupId,
String artifactId)
从 Maven 构建过程中生成的 pom.properties 文件中读取版本号。
|
static void |
main(String[] args)
主函数示例:演示如何使用不同方法获取当前类的版本号。
|
public static String getJarVersion(Class<?> clazz) throws IOException
clazz - 指定要查询版本的类对象,不能为 nullIOException - 如果在访问 JAR 或 MANIFEST 过程中出现 IO 异常public static String getVersionFromPackage(Class<?> clazz)
clazz - 指定要查询版本的类对象,不能为 nullpublic static String getVersionFromPomProperties(Class<?> clazz, String groupId, String artifactId)
clazz - 当前类对象,用于定位资源路径groupId - Maven 坐标中的 groupIdartifactId - Maven 坐标中的 artifactIdpublic static void main(String[] args) throws IOException
args - 启动参数(未使用)IOException - 若调用 getJarVersion 方法时发生 IO 错误Copyright © 2026. All rights reserved.