开发者

specify db password in ant build file

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜