2016-10-10 51 views
0

變量是否有可能從NBI(安裝項目)的ant腳本訪問在platform.properties定義文件中的變量,如nbjdk.active這是設置好的,當一個項目Java平臺改變了嗎?訪問platform.properties從NBI ant腳本

目標是從ant腳本中選擇一個打包的jre(32或64)作爲這個變量的函數。

在此先感謝。

編輯: 這是當我嘗試訪問該變量的構建腳本片斷:

<target name="-generate-bundles"> 
    <for-each property="platform" list="${target.platforms}" separator=" "> 

     <condition property="bundle.extention.${platform}" value="exe"> 
      <contains string="${platform}" substring="windows"/> 
     </condition> 
     <condition property="bundle.extention.${platform}" value="sh"> 
      <or> 
       <contains string="${platform}" substring="linux"/> 
       <contains string="${platform}" substring="solaris"/> 
      </or> 
     </condition> 
     <condition property="bundle.extention.${platform}" value="zip"> 
      <contains string="${platform}" substring="macosx"/> 
     </condition> 

     <set property="bundle.extention" source="bundle.extention.${platform}"/> 

     <create-bundle root="${output.dir}/registry-temp" 
        platform="${platform}" 
        target="${bundles.release.dir}/${bundle.files.prefix}-${platform}.${bundle.extention}"> 
      <component uid="${main.product.uid}" version="1.0.0.0.0"/> 


      <!-- HERE I WANT TO CHECK THE VARIABLE AND SELECT ONE OF THE PACKED JRE --> 
      <!--<property name="nbi.bundled.jvm.file" value="D:\packed\jre1.8.0_65_32bits\jre.exe"/>--> 
      <property name="nbi.bundled.jvm.file" value="D:\packed\jre1.8.0_25_64bits\jre.exe"/> 

     </create-bundle> 

     <echo>************************</echo> 
     <echo>********* OS: ${platform}</echo> 
     <echo>********* Arch: ${os.arch}</echo> 
     <echo>********* JDK in NB: ${jdk.home}</echo> 
     <echo>********* JDK in platform.properties: HERE I TRY TO ACCESS VARIABLE</echo> 
     <echo>************************</echo> 


     <if property="bundle.extention" value="zip"> 
      <antcall target="zip-to-tgz"> 
       <param name="input.file" value="${bundles.release.dir}/${bundle.files.prefix}-${platform}.zip"/> 
       <param name="output.file" value="${bundles.release.dir}/${bundle.files.prefix}-${platform}.tgz"/> 
      </antcall> 
     <delete file="${bundles.release.dir}/${bundle.files.prefix}-${platform}.zip"/> 
     </if> 
    </for-each> 
    <echo>Installer(s) for [${target.platforms}] are available at ${bundles.release.dir}</echo> 
</target> 

,這是platform.properties文件中的變量:

nbjdk.active=JDK_1.8.0_65-32bits 
+0

你可以請你展示你當前的構建腳本和正在面臨的確切問題嗎? – Rao

+0

有沒有解決這個問題的提示? – pacobm

+0

至少我想如果這是可能實現的,有人可以告訴我這個嗎? – pacobm

回答

0

這裏是將在構建腳本中訪問的屬性文件內容:

下面的構建腳本示例顯示如何訪問屬性abc這是從test.properties文件。

所有你需要的是訪問它使用所示的腳本,當然之前加載屬性文件,改變屬性的文件路徑根據您的環境。徘徊無論是需要它的值如下面的echo任務

<property file="D:/Temp/test.properties"/> 

然後使用${abc}

test.properties內容

abc=123 
def=234 

的build.xml

<project name="imported" basedir="." default="test"> 
    <property file="D:/Temp/test.properties"/> 
    <target name="test" description="check if the property can be retrieved from file"> 
    <echo message="Property abc's value from file is ${abc}"/> 
    </target> 
</project> 

輸出

test: 
    [echo] Property abc's value from file is 123 

BUILD SUCCESSFUL 
Total time: 0 seconds 
[Finished in 4.7s] 

希望這很有幫助。

+0

感謝您的回答,但這不是問題的範圍。問題是關於NetBeans項目,如果可以從ant構建腳本訪問platform.properties文件中定義的變量。如果你看到我附加的代碼,我可以訪問一些環境變量,但是可以從platform.properties文件中獲取。 – pacobm

+0

答案顯示如何從文件訪問屬性。 'nbjdk.active'在你提供的ant腳本中沒有涉及。你能更清楚地瞭解這個問題嗎?錯誤? – Rao

+0

在' *********在platform.properties中的JDK:這裏我嘗試訪問變量'是我想要訪問這個變量的地方。 – pacobm