Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6846017
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T00:34:17+00:00 2026-05-27T00:34:17+00:00

working on an ANT build file, where I have two macros defined and need

  • 0

working on an ANT build file, where I have two macros defined and need to call one Macro from other.

Here is what I need to do (I have simplified the whole scenario for easy understanding). My main target calls FirstMacro with two params. The First Macro needs to do “something” with two params received and make an embedded call to SecondMacro.

One of the params passed to FirstMacro is a file path with “backslash” () in it. When I print it in the macro using echo it prints fine. But when I pass the same parameter to SecondMacro via JavaScript, the backslashes are gone (instead of C:\Test I see C:Test).
What is the solution to preserve the backslash or replace them with forward slash.

Note that I am using ANT 1.7 and I have already tried string.replace(/\/g,”/”) etc.

Also note that, you can copy paste the entire code below, save it as build.xml and try running the main task to see the issue in running.

<?xml version="1.0"?>
<project name="build" basedir="." default="main">
    <description>
    ==========================
    Macro: Second Macro
    ==========================
    </description>
    <macrodef name="secondMacro">
        <attribute name="param"/>

        <sequential>
            <echo>secondMacro param: @{param}</echo>
        </sequential>
    </macrodef>

    <description>
    ==========================
    Macro: FirstMacro
    ==========================
    </description>
    <macrodef name="firstMacro">
        <attribute name="param1"/>
        <attribute name="param2"/>

        <sequential>
            <echo>firstMacro first param: @{param1}</echo>
            <echo>firstMacro second param: @{param2}</echo>
            <script language="javascript">
                <![CDATA[
                    var ext = "@{param2}";
                    if ("".equals(ext)) {
                        ext = "out";
                    }

                    macrotask = project.createTask("secondMacro");
                    macrotask.setDynamicAttribute("param", "@{param1}" + "."+ext );
                    macrotask.perform();
                ]]>
            </script>
        </sequential>
    </macrodef>

    <description>
    ==========================
    Target: main target
    ==========================
    </description>
    <target name="main">

        <firstMacro param1="C:\TestFolder/TestFile" param2=""/>
    </target>
</project>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T00:34:18+00:00Added an answer on May 27, 2026 at 12:34 am
    <firstMacro param1="C:\\TestFolder/TestFile" param2=""/>
    

    prints

    main:

    [echo] firstMacro first param: C:\TestFolder/TestFile
    [echo] firstMacro second param:
    [echo] secondMacro param: C:\TestFolder/TestFile.out

    It should be your JS code’s problem. I know little about JS, but backslash means “this is an escape character” in most languages. So when JS see a single backslash, it may regard it as an escape character and do some convertion… Even if you use beanshell or something else, similar thing may happen.

    To solve the problem, you can try to modify your JS code (which I can’t help, sorry) or try to use slash (/) instead of backslash.

    Update: you can use the if task from ant-contrib.
    Here is the example of the if-task version “firstMacro”.

    <macrodef name="firstMacro">
        <attribute name="param1"/>
        <attribute name="param2"/>
        <sequential>
            <echo>firstMacro first param: @{param1}</echo>
            <echo>firstMacro second param: @{param2}</echo>
            <if>
                <equals arg1="@{param2}" arg2="" />
                <then>
                    <property name="param" value="@{param1}.out" />
                </then>
                <else>
                    <property name="param" value="@{param1}.@{param2}" />
                </else>
            </if>
            <secondMacro param="${param}" />
        </sequential>
    </macrodef>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am converting ant to maven2. In build.xml, I have: <target name=clean> <delete file=${dir.dist}/${api.jarfile}
I am having issues integrating junit with a working ant build.xml file. My test
I'm working on a new project with a full ANT build. I use eclipse
I am working on an Ant target for running tests, and I need to
I've written an Ant build.xml file which obtains a number of source files via
I'm working on a project that uses NetBeans to generate the ANT build files.
Greeting, I'm trying to put some Beanshell script in my Ant build.xml file. I've
I have a build file in which I have a tasks as below //tomcat
I have a project which I can build and deploy correctly using Ant I
I have been using this exact Build.xml file. I had problems in the beginning

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.