把版本放到我的java应用程序 - Netbeans

Jin*_*ith 10 java netbeans version

有什么办法可以在netbeans中为我的应用程序提供版本号.然后在我的代码中访问该版本号.

类似于我们在.Net中使用的程序集编号的东西.在java或netbeans中有类似的东西......?

And*_*son 12

Implementation-Version在构建时在Jar的清单中定义一个.通常使用某种形式的日期作为版本号.例如14.07.28

可以使用..在代码中检索该值.

String version = this.getClass().getPackage().getImplementationVersion();
Run Code Online (Sandbox Code Playgroud)
<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>
Run Code Online (Sandbox Code Playgroud)

这来自我目前打开的项目的构建文件.相关属性是清单部分中的最后一个属性.