Mostrando entradas con la etiqueta filterset. Mostrar todas las entradas
Mostrando entradas con la etiqueta filterset. Mostrar todas las entradas

lunes, 10 de enero de 2011

How to replace strings with ant

If you have a file where some strings have to be automatically replaced during the deployment, you can use the filterset ant command like in the example:

<target name="replaceString" description="Replace host name and port String">
        <copy todir="tmp/myTemporaryDirectory">
            <filterset>
              <filter token="REMOTE_HOST_NAME" value="${remote.host.name}"/>
              <filter token="REMOTE_HOST_PORT" value="${remote.host.port}" />
            </filterset>
            <fileset dir="./directoryContainingFileWithStringsToBeReplaced">
                <include name="myHost.jsp" />
                <include name="backupHost.jsp" />
            </fileset>
        </copy>       
    </target>

In your files myHost.jsp and backupHost.jsp there will be the following String:
@REMOTE_HOST_NAME@ and @REMOTE_HOST_PORT@
for any occurence of them, something like:

./directoryContainingFileWithStringsToBeReplaced/file.jsp:
String urlString = "http://@REMOTE_HOST_NAME@:@REMOTE_HOST_PORT@/jsp/file.jsp?";

Do not forget to use the directory tmp/myTemporaryDirectory, where your replacement have been executed!!