You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@maven.apache.org by Ben Anderson <be...@benanderson.us> on 2004/11/01 16:06:14 UTC
Re: dynamic property access
Thanks Alex - that works! However, I've realized I don't really need to do
this. If anyone cares, here's my resolution that lets me add tokens to
property files dynamically w/out requiring a change in my maven.xml. Nothing
special here - I just think it's pretty neat.
<goal name="prop">
<j:set var="envDir">.${env}</j:set>
<ant:copy toDir="${maven.build.dest}"
overwrite="true">
<ant:fileset dir="${maven.src.dir}"
includes="*.properties"/>
<ant:filterset>
<u:properties var="props"
file="${basedir}/../../environment/environment.properties"/>
<j:forEach var="prop" items="${props}">
<j:choose>
<j:when test="${prop.key.endsWith(envDir)}">
<j:set var="propKey">
${prop.key.substring(0, prop.key.indexOf(envDir))}
</j:set>
<ant:filter token="${propKey}" value="${prop.value}"/>
</j:when>
<j:when test="${!(prop.key.endsWith('qa') or
prop.key.endsWith('prod'))}">
<ant:filter token="${prop.key}" value="${prop.value}"/>
</j:when>
</j:choose>
</j:forEach>
</ant:filterset>
</ant:copy>
</goal>
environment.properties
----------------------
server.name.qa=myQABox
server.name.prod=myProdBox
server.port=80
Some properties file to be filtered
-----------------------------------
serverName=@server.name@
serverPort=@server.port
now I can run:
maven -Denv=qa|prod someGoal
-Ben
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org