开发者

specify db password in ant build file

开发者 https://www.devze.com 2023-01-28 00:00 出处:网络
my webapp has a hibernate config file that specifies db password as follows: <property 开发者_StackOverflowname="hibernate.connection.password">p1ssw2rd</property>

my webapp has a hibernate config file that specifies db password as follows:

 <property 开发者_StackOverflowname="hibernate.connection.password">p1ssw2rd</property>
it also has an ant build file, is it possible to specify the db password at build time and then pass it to hibernate?


    <target name="init-development">

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


You can create template hibernate config with password label like this:

<property name="hibernate.connection.password">@@HIBER_PASSWORD@@</property>

and when ant starts a build, copy template config over real hibernate config, applying replacement password label with real db password specified in build.xml. It is like that:

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


I changed the section <replacetokens> <token key="@@HIBER_PASSWORD@@" value="${databasePassword}"/> </replacetokens>

for replaceString

:D It works

0

精彩评论

暂无评论...
验证码 换一张
取 消