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

  • SEARCH
  • Home
  • 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 3980438
In Process

The Archive Base Latest Questions

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

I wrote a small macrodef in separate file: macrodefs.xml <macrodef name=do-cool-stuff> <attribute name=message/> <sequential>

  • 0

I wrote a small macrodef in separate file:

macrodefs.xml

<macrodef name="do-cool-stuff">
  <attribute name="message"/>

  <sequential>
    <echo message="@{message}" />
  </sequential>
</macrodef>

I got a second file, my main build file:

build.xml

<target name="build">
  <!-- do this and that -->

  <!-- cheking out macrodefs.xml via CVS -->

  <ant antfile="macrodefs.xml" target="do-cool-stuff" >
    <property name="message" value="Hello, World!" />
  </ant>
</target>

As you might guess this dosen’t work. The error message is something like:

Target 'do-cool-stuff' does not exist in this project.

The only possible solution I found is to provide a extra target in the macrodefs.xml to forward the ant calls.

Is there a possibility to invoke the macrodef from within another file?

Thanks in advance.

  • 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-20T05:17:28+00:00Added an answer on May 20, 2026 at 5:17 am

    You can import the file and use the macro like this:

    <import file="macrodefs.xml" />
    <do-cool-stuff message="Hello, World!" />
    

    Note that in the macro definition you should use @{curlybrackets} when referencing macro attributes:

    <sequential>
        <echo message="@{message}" />
    </sequential>
    

    There are some examples at the end of the Ant macrodef task docs.

    More

    What you’re trying to do isn’t well supported by Ant. The ant and antcall tasks don’t allow the ‘callee’ to affect the caller directly. You can write files in the called task, then load those in the caller. But as you have observed, the pre-process tasks import and include cannot be called from within a target. The ant/antcall tasks only allow you to run targets in subsidiary builds, not macros.

    One workaround method (this might be similar to the one you mention, but allows you to put all the real work in the top-level build) would be to have an inner buildfile that includes the top-level import of the macrodefs.xml.

    Something like the following. The macrodefs.xml file is as before. (But note that the imported files – including the macro definitions – need to be complete Ant project files, so they must include a project element.)

    build.xml:

    <target name="build">
        <!-- cvs actions -->
        <ant antfile="inner-build.xml" target="target-runner">
            <property name="target" value="top-target" />
        </ant>
    </target>
    
    <!-- this target will fail unless invoked from the inner build -->
    <target name="top-target">
        <do-cool-stuff message="Hello, World!" />
    </target>
    

    inner-build.xml:

    <project>
        <import file="macrodefs.xml" />
    
        <target name="target-runner">
            <ant antfile="build.xml" target="${target}" />
        </target>
    </project>
    

    Effectively you would be doing

    build.xml --> inner-build.xml --> build.xml (again)
    (cvs)         (import macros)     (use macros)
    

    The inner buildfile could potentially be generated on-the-fly by the main build – say if you wanted to import multiple macro definition files – but that’s getting perhaps too unwieldy.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I wrote a small script, which parses a XML-file, deletes some redundant elements and
I wrote a small PHP script to edit the site news XML file. I
I wrote a small C# Tool deleting all comments within a word file using
I wrote a small executable in C# .NET that manages a .jar file. Our
I wrote a small batch file to rar all contents in all subfolders within
I wrote this small C program: #include <stdio.h> #include <stdlib.h> int main() { FILE
I wrote a small PHP application several months ago that uses the WordPress XMLRPC
I wrote a small PHP application that I'd like to distribute. I'm looking for
We wrote a small Windows class library that implements extension methods for some standard
I wrote a small sample of code in C# to capture selected text from

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.