2016-10-10 33 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