2016-04-10 109 views
1

BenAnt - .properties değişkenleri kullanılarak

Benim Build.xml

<target name="configure"> 
    <echo message="Creating DB configuration" /> 
    <copy todir="${dir.out}" overwrite="true"> 
     <fileset dir="${dir.in}" /> 
     <filterchain> 
     <expandproperties/> 
     <replacetokens begintoken="&lt;" endtoken="&gt;" propertiesResource="conf.properties" /> 
     </filterchain> 
    </copy> 
    </target> 
içeren ** ile kopya görevi kullanarak .properties dosyasında tanımlanan değerlerle kaynak dosyalarında yer tutucular yerine çalışıyorum dosyaları conf.properties gelen

bir örnek: Ben bu durumda ben istiyorum, değişkenlere .properties dosyasından içinden başvurmak isteyen

tbs.base_directory = d:/oracle/oradata/my_app 
tbs.data_file = ${tbs.base_directory}/data01.dbf 

tbs.base_directory'un tbs.data_file ile değiştirilmesi.

Maalesef bu değiştirilemedi. Herhangi bir fikir?

Teşekkür

cevap

1

Sorun expandproperties Eğer belirteçleri tanımlamak için kullandığınız özellik kaynağına değil kopyalanan dosya için geçerlidir olmasıdır. Olası bir çözüm, özellikleri genişletmeye zorlamak ve belirteç değiştirme için kullanılan geçici bir dosyaya dökmek üzere ilk olarak conf.properties yüklenmektir. aşağıdaki gibi bir şey çalışmalıdır: Bu çözümün

<target name="configure"> 
    <echo message="Creating DB configuration" /> 
    <!-- force expanding properties in tokens property file --> 
    <loadproperties srcfile="conf.properties" /> 
    <!-- dump expanded properties in a temp file --> 
    <echoproperties prefix="tbs" destfile="conf.expanded.properties"/> 
    <copy todir="${dst.out}" overwrite="true"> 
      <fileset dir="${dir.in}" /> 
      <filterchain> 
       <expandproperties/> 
      <!-- use temporary file for token substitution --> 
      <replacetokens begintoken="&lt;" endtoken="&gt;" propertiesResource="conf.expanded.properties" /> 
      </filterchain> 
    </copy> 
    <!-- delete temp file (optinal)--> 
    <delete file="conf.expanded.properties"/> 
</target> 

Dezavantajı geçici dosya (yazmayı özelliklerini seçebilir olarak sadece sürece çalışır olmasıdır yani conf.properties dosyadaki tüm özellikler aynı öntakıya).