在java类或jsf页面中设置当前编译时间
我和maven一起整理了一份战争档案。 我想在jsf页面中插入编译时间戳 如何在编译时更改jsf页面中的字符串? 范例在java类或jsf页面中设置当前编译时间,java,maven,jsf,Java,Maven,Jsf,我和maven一起整理了一份战争档案。 我想在jsf页面中插入编译时间戳 如何在编译时更改jsf页面中的字符串? 范例 我想你说的是通过maven resources插件进行资源过滤的一种变体。这个想法是: 您要求Maven通过Maven resources插件过滤特定资源,或者是src/main/resources资源,或者是它的变体,或者是通过Maven war插件过滤src/main/webapp资源,在Maven war插件中您已经放置了Maven预定义变量${Maven.build.t
我想你说的是通过maven resources插件进行资源过滤的一种变体。这个想法是: 您要求Maven通过Maven resources插件过滤特定资源,或者是src/main/resources资源,或者是它的变体,或者是通过Maven war插件过滤src/main/webapp资源,在Maven war插件中您已经放置了Maven预定义变量${Maven.build.timestamp} 确保已筛选的资源包含在项目中 您可以通过Class.getResourceAsStream或其变体读取该资源,也可以根据放置位置通过servlet机制读取该资源。 您可以在JSF中使用该值。 请注意,您可以要求Maven直接在JSF中替换一个过滤器和一个变量,并减少一些步骤。从中您可以获得一个文件的引用:
final File classFile = new File(MyApp.class.getProtectionDomain().getCodeSource().getLocation().getPath());
然后从你那里得到财产:
BasicFileAttributes attr = Files.readAttributes(classFile, BasicFileAttributes.class);
String compilationTime = attr.creationTime().toString();
您可以使用和创建字段
@CompileTime
private static long ct; // This field will contain compilation time in ms
我不知道这是否正是您所请求的,但您可以使用maven生成一个名为version.properties的包文件,例如,使用maven buildnumber插件:然后从文件内容而不是从变量中检索信息。1文件创建时间和编译时间不一定相同。可以复制文件。2如果类是从JAR文件加载的,那么这将不起作用。
public class MyApp{
String compilationTime = 'xxxx';
public String getCompilationTime(){
return compilationTime;
}
}
final File classFile = new File(MyApp.class.getProtectionDomain().getCodeSource().getLocation().getPath());
BasicFileAttributes attr = Files.readAttributes(classFile, BasicFileAttributes.class);
String compilationTime = attr.creationTime().toString();
@CompileTime
private static long ct; // This field will contain compilation time in ms