Jinith Jinith - 10 months ago 67
Java Question

Put version to my java application - 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.

Something similar to the Assembly number that we use in .Net.Is there anything like that in java or in netbeans...?

Answer Source

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();

    <format property="now" pattern="yy.MM.dd"/>
    index='true' >
        <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}"/>
    <fileset dir="build/share">
        <include name="${package.name}/*.class" />
        <include name="${package.name}/*.png" />

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.