把版本放到我的java应用程序 - Netbeans [英] Put version to my java application - Netbeans
问题描述
有没有办法可以在netbeans中为我的应用程序提供版本号。然后在我的代码中访问该版本号。
Is there any way that i can give a version number to my application in netbeans.And then access that version number inside my code.
类似于程序集的东西我们在.Net中使用的数字。在java或netbeans中有类似的东西......?
Something similar to the Assembly number that we use in .Net.Is there anything like that in java or in netbeans...?
推荐答案
在Jar的清单中定义 Implementation-Version
建立时间。通常使用某种形式的日期作为版本号。例如。 14.07.28
Define an Implementation-Version
in the manifest of the Jar at build time. It is common to use some form of the date as the version number. E.G. 14.07.28
可以使用..在代码中检索该值。
The value can be retrieved in code using..
String version = this.getClass().getPackage().getImplementationVersion();
<tstamp>
<format property="now" pattern="yy.MM.dd"/>
</tstamp>
...
<jar
destfile="build/dist/lib/${jar.name}"
update='true'
index='true' >
<manifest>
<attribute name="Created-By" value="${vendor}"/>
<attribute name="Implementation-Title" value="${application.title}"/>
<attribute name="Implementation-Vendor" value="${vendor}"/>
<attribute name="Implementation-Vendor-Id" value="org.pscode"/>
<!-- This next property is retrieved in code above. -->
<attribute name="Implementation-Version" value="${now}"/>
</manifest>
<fileset dir="build/share">
<include name="${package.name}/*.class" />
<include name="${package.name}/*.png" />
</fileset>
</jar>
这来自我目前打开的项目的构建文件。相关属性是清单部分中的最后一个属性。
This comes from a build file for a project I have open at the moment. The relevant attribute is the last one in the manifest section.
这篇关于把版本放到我的java应用程序 - Netbeans的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!