我有一个名为 BuildNumberService 的简单服务,它将由 spring 实例化。
我正在尝试为该类找到最干净的代码,以从它已打包到的 jar 文件中找出 MANIFEST.MF 文件。
代码必须在 servlet 容器中运行。
@Service
public class BuildNumberService {
private static final String IMPLEMENTATION_BUILD = "Implementation-Build";
private String version = null;
public BuildNumberService() {
// find correct manifest.mf
// ?????
// then read IMPLEMENTATION_BUILD attributes and caches it.
Attributes mainAttributes = mf.getMainAttributes();
version = mainAttributes.getValue(IMPLEMENTATION_BUILD);
}
public String getVersion() {
return this.version;
}
}
你会怎么做?
编辑:实际上,我想做的是,按名称查找与实际类位于同一包中的资源。