在纯 JSF2.0应用程序中访问Manifest属性(来自/META-INF/Manifest.mf)的最佳方法是什么?
答案 0 :(得分:4)
对于McDowell上面的建议,改进的init()
变为:
@PostConstruct
public void init() {
try {
InputStream is = FacesContext.getCurrentInstance().getExternalContext().getResourceAsStream("/META-INF/MANIFEST.MF");
manifest = new Manifest();
manifest.read(is);
} catch (IOException ioe) {
logger.error("Unable to read the Manifest file from classpath.", ioe);
}
}
答案 1 :(得分:0)
以下似乎有效:
创建ManagedBean:
@ManagedBean(name = "cic")
@ApplicationScoped
public class ConfigurationInformationController {
private static final Logger logger = LoggerFactory.getLogger(ConfigurationInformationController.class.getName());
private Manifest manifest = null;
public Manifest getManifest() {
return manifest;
}
@PostConstruct
public void init() {
File manifestFile = null;
try {
String home = FacesContext.getCurrentInstance().getExternalContext().getRealPath("/");
manifestFile = new File(home, "META-INF/MANIFEST.MF");
manifest = new Manifest();
manifest.read(new FileInputStream(manifestFile));
} catch (IOException ioe) {
logger.error("Unable to read the Manifest file from '"+manifestFile.getAbsolutePath()+"'",ioe);
}
}
}
在Facelets页面中,从那里调用属性......
<h:outputLabel for="Build-BuildTimestamp" value="Build Timestamp:"/>
<h:outputText id="Build-BuildTimestamp" value="#{cic.manifest.mainAttributes.getValue('Build-BuildTimestamp')}"/>