Put version to my java application - Netbeans

前端 未结 3 1786
轮回少年
轮回少年 2021-02-08 15:07

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 num

相关标签:
3条回答
  • 2021-02-08 15:30

    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.

    0 讨论(0)
  • 2021-02-08 15:33

    I don't know about .NET assembly numbers, but if you're creating a web application you can certainly put a version number into the manifest of your WAR file.

    Any Java package can have a build info text file added to it so you can tell these things.

    Your version number could be a build number from Ant, a version number from Subversion, or a combination of the two.

    0 讨论(0)
  • 2021-02-08 15:45

    In my JavaFX app created in Netbeans, I can set the build version (Implementation version) in the Project Properties window shown here:

    This number is then used everywhere, for example it is automatically inserted into the filename of the installer. It is also the number retrieved by this.getClass().getPackage().getImplementationVersion(); mentioned by the accepted answer.

    0 讨论(0)
提交回复
热议问题