2010-12-01 48 views
0

我的webapp有一個hibernate配置文件,它指定db密碼,如下所示:在ant構建文件中指定db密碼

 
<property name="hibernate.connection.password">p1ssw2rd</property> 
它也有一個ant構建文件,是否可以在構建時指定db密碼,然後將它傳遞給冬眠?

 

    <target name="init-development"> 

     <property name="databasePassword" value="xxxx"/> 
    </target> 

回答

2

您可以創建模板冬眠的配置,像這樣的密碼標籤:

<property name="hibernate.connection.password">@@[email protected]@</property> 

,當螞蟻開始構建,複製模板配置在實際休眠配置,指定與真正DB更換密碼密碼標籤粘貼在build.xml中。 它是這樣的:

<copy file="${src.dir}/hibernate-config.xml.tpl" 
     tofile="${src.dir}/hibernate-config.xml"> 
    <filterchain> 
      <replacetokens> 
       <token key="@@[email protected]@" 
         value="${databasePassword}"/> 
      </replacetokens> 
    </filterchain> 
</copy> 
0

我改變了部分 <replacetokens> <token key="@@[email protected]@" value="${databasePassword}"/> </replacetokens>

爲replaceString

:d 它的工作原理