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 8402905
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T22:12:05+00:00 2026-06-09T22:12:05+00:00

I’m in a situation that involves running an ant build with optional parameters that

  • 0

I’m in a situation that involves running an ant build with optional parameters that are always specified but but not always defined, like so

ant -DBUILD_ENVIRONMENT=test -Dusername_ext= -Dconf.dir_ext= -Dcgi-dir_ext=

If the parameters are not given values on the command line they will be by loading a .properties file. I have the following code that will check if the property isset and is not blank.

<if>
    <bool>
        <and>
            <isset property="username_ext"/>
            <not>
                <equals arg1="${username_ext}" arg2="" />
            </not>
        </and>
    </bool>
    <then>
        <property name="username" value="${username_ext}" />
    </then>
</if>
<property file="${BUILD_ENVIRONMENT}.properties" />

Since there are multiple properties it seems like I should write a target that will do the same actions for each property rather than repeat that code every time.

<antcall target="checkexists">
    <property name="propname" value="username"/>
    <property name="paramname" value="username_ext"/>
</antcall>
<antcall target="checkexists">
    <property name="propname" value="conf.dir"/>
    <property name="paramname" value="conf.dir_ext"/>
</antcall>

But AFAIK an antcall will not set a global property. How then can I write a target that will accept the name of a parameter it needs to check is set and is not blank, and then copy that in to a parameter that other targets can use?

  • 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-06-09T22:12:06+00:00Added an answer on June 9, 2026 at 10:12 pm

    Rather than using a target you could use a macro to conditionally set properties based on whether or not another property is set to a non-empty value.

    <macrodef name="set-property">
      <attribute name="name" />
      <attribute name="if-property-isset" />
      <attribute name="value" default="${@{if-property-isset}}" />
    
      <sequential>
        <condition property="@{name}" value="@{value}">
          <and>
            <isset property="@{if-property-isset}" />
            <not>
              <equals arg1="${@{if-property-isset}}" arg2="" />
            </not>
          </and>
        </condition>
      </sequential>
    </macrodef>
    
    
    <target name="test-macro">
      <set-property name="username" if-property-isset="username_ext" />
    
      <set-property name="conf.dir" if-property-isset="conf.dir_ext" />
    
      <property name="conf.dir" value="default conf directory" />
    
      <echo message="username = ${username}" />
      <echo message="conf.dir = ${conf.dir}" />
    </target>
    

    Output

    $ ant test-macro -Dusername_ext=jsmith -Dconf.dir_ext=
    Buildfile: /your/project/build.xml
    
    test-macro:
         [echo] username = jsmith
         [echo] conf.dir = default conf directory
    
    BUILD SUCCESSFUL
    Total time: 1 second
    

    Alternate Property Value

    This macro also allows you set the property to a different value than the one provided on the command line.

    <target name="test-macro">
      <set-property name="username" if-property-isset="username_ext"
          value="It worked!" />
    
      <set-property name="conf.dir" if-property-isset="conf.dir_ext" />
    
      <property name="conf.dir" value="default conf directory" />
    
      <echo message="username = ${username}" />
      <echo message="conf.dir = ${conf.dir}" />
    </target>
    

    Output

    $ ant test-macro -Dusername_ext=jsmith -Dconf.dir_ext=
    Buildfile: /your/project/build.xml
    
    test-macro:
         [echo] username = It worked!
         [echo] conf.dir = default conf directory
    
    BUILD SUCCESSFUL
    Total time: 1 second
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a French site that I want to parse, but am running into
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace
I am doing a simple coin flipping experiment for class that involves flipping a
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I need a function that will clean a strings' special characters. I do NOT
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I want to count how many characters a certain string has in PHP, but
I would like to count the length of a string with PHP. The string

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.