How to convert path slashes during build

It happens many times that you need to set a property using path defined in the build process and convert slashes according to the relevant OS, and do it while coping the property file to the target directory during build.
Here is a simple example how to do it with Ant:

let's say mypath is defined as "module\conf\xml"
in your my.properties the path should appear as:
MY_NEW_PATH=@mypath@/more/xxx

in your build.xml (or in pom.xml when using antrun plugin with maven):
<pathconvert property="mypathfixed" dirsep="/">
         <path location="${mypath}"/>
</pathconvert>
<copy todir="${my.target_dir}" filtering="true">
            <fileset dir="${basedir}/src/main/conf" includes="my.properties"/>
            <filterset recurse="true">
                  <filter token="mypath" value="${mypathfixed}"/>
            </filterset>
</copy>

copied my.properties will have your property defined as:
MY_NEW_PATH=
module/conf/xml/more/xxx

More useful examples how to use pathconvert: http://ant.apache.org/manual/CoreTasks/pathconvert.html

DevOps Architect

DevOps Group
Thank you for your interest!

We will contact you as soon as possible.

Send us a message

Oops, something went wrong
Please try again or contact us by email at info@tikalk.com