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
精彩评论