2016-04-10 14 views
1

を使用して、私は**アリ - .propertiesファイル内の変数

コピータスクを使用しての.propertiesファイルで定義された値とソースファイルのプレースホルダを置き換えるためにしようとしています私の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> 
が含まれています

conf.propertiesからサンプル:

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

私はこのケースでは、私は希望、変数に.propertiesファイル内から参照したいですtbs.base_directoryに置き換えます。tbs.data_file

残念ながら、それは置き換えられません。何か案は?

おかげ

答えて

1

問題expandpropertiesがあなたのトークンを定義するために使用されているプロパティのリソースにないコピーしたファイルに適用されることです。考えられる解決策は、最初にconf.propertiesをロードしてプロパティ展開を強制し、トークンの置換に使用される一時ファイルにダンプします。以下のような何か作業をする必要があります:このソリューションの

<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> 

欠点は、それが唯一の限り、あなたは一時ファイルに書き込むようにプロパティを選択することができますように動作することである(conf.propertiesファイル内すなわち、すべてのプロパティが同じ接頭辞で始まります)。

関連する問題