maven-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Ben Anderson <benander...@benanderson.us>
Subject Re: dynamic property access
Date Mon, 01 Nov 2004 15:06:14 GMT
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


Mime
View raw message