在此先感谢您的帮助。
我想要实现的是项目版本 ( Implementation-Version) 在启动时打印在一个类中,以便我可以从日志文件中跟踪版本。
我构建了一个包含以下类的 JAR 文件:
com.company.core.common.ClassA
com.company.core.security.ClassB
com.company.core.sql.ClassC
Run Code Online (Sandbox Code Playgroud)
在 的构造函数中com.company.core.sql.ClassC,我想通过调用 来调用System.out.println()打印出Implementation-Version存储在META-INF/MANIFEST.MF文件中的内容this.class.getPackage().getImplementationVersion(),但是null当通过 Maven 测试类启动该类时,它正在获取值。
我的MANIFEST.MF文件包含以下详细信息:
Manifest-Version: 1.0
Implementation-Title: Company Core Library
Implementation-Version: 1.0
Archiver-Version: Plexus Archiver
Built-By: simon
Implementation-Vendor-Id: com.company.core
Build-Time: 2017-02-18T15:07:33Z
Class-Path: lib/sqljdbc42-4.2.jar lib/log4j-api-2.7.jar lib/log4j-core
-2.7.jar lib/json-20160810.jar lib/junit-4.12.jar lib/hamcrest-core-1
.3.jar
Created-By: Apache Maven 3.3.9
Build-Jdk: 1.8.0_102
Implementation-Vendor: Company
Name: com/company/core/
Implementation-Vendor-Id: com.company.core
Implementation-Title: Company Core Library
Implementation-Version: 1.0
Implementation-Vendor: Company
Run Code Online (Sandbox Code Playgroud)
我能得到Implementation-Version …