2011-03-05 46 views

回答

11

在構建時在Jar的清單中定義Implementation-Version。通常使用某種形式的日期作爲版本號。例如。 14.07.28

值可以在代碼中使用檢索..

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> 

這來自於一個項目,我目前所面對的開放構建文件。相關屬性是清單部分中的最後一個。

+0

有關如何使用netbeans設置此任何想法? – Jinith 2011-03-05 14:31:43

+0

我不使用netbeans,但我知道NetBeans理解Ant構建文件,並且從構建文件中完成它是相對平凡的。我會調整答案給一個小例子的Ant例子。 – 2011-03-05 18:51:19

1

我不知道.NET程序集編號,但如果您創建的是Web應用程序,那麼您肯定可以將一個版本號放入WAR文件的清單中。

任何Java包都可以有一個構建信息文本文件添加到它,所以你可以告訴這些事情。

您的版本號可能是來自Ant的版本號,來自Subversion的版本號或兩者的組合。

+0

我如何獲得內部版本號?我必須將自己的內部版本號放入文本文件還是生成? – Jinith 2011-03-05 14:29:34

+0

http://www.rgagnon.com/javadetails/java-0532.html – duffymo 2011-03-05 15:41:45

1

在NetBeans中創建我的JavaFX應用程序,我可以在這裏設置顯示在項目屬性窗口中的生成版本(試行版): Screenshot of Netbeans Project Properties

該號碼,然後使用無處不在,例如,它會自動插入安裝程序的文件名。它也是由接受的答案提到的this.getClass().getPackage().getImplementationVersion();檢索的數字。