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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T19:50:08+00:00 2026-05-20T19:50:08+00:00

Dear, I currently face some problem to retrieve the value of a property setted

  • 0

Dear, I currently face some problem to retrieve the value of a property setted in a foreach loop. Maybe one of you could help me…

The purpose is to check if one file of a folder has been modified since the corresponding jar has been generated. This way I know if I have to generate the jar again.
What I do is to go through the folder with a foreach loop and if one file match my test, set a property to true.

The problem is that my variable doesn’t seems to exist after my loop… Here is a simplified code example that has the same problem:

<target name="target">
    <taskdef resource="net/sf/antcontrib/antlib.xml" classpath="${lib.dir}/ant-contrib.jar"></taskdef>
    <foreach target="setVar" param="var" list="a,b"/>
    <echo>myreturn in target: ${env.myreturn}</echo>
    <property name="env.myreturn" value="c"/>
    <echo>myreturn in second: ${env.myreturn}</echo>
</target>
<target name="setVar">
    <property name="env.myreturn" value="${var}"/>
    <echo>myreturn in setVar: ${env.myreturn}</echo>
</target>

The result of this code is:

target:
setVar:
 [echo] myreturn in setVar: a
setVar:
 [echo] myreturn in setVar: b
 [echo] myreturn in target: ${env.myreturn}
 [echo] myreturn in second: c
BUILD SUCCESSFUL

It seems that the variable is correctly set as it could be printed in the “setVar” target but no way to retrieve value from the calling target.

I also know it’s not possible to assign a value to a property twice. But the problem doesn’t even occurs… When it’ll be the case I could add a check on the value of the property before to assign it to be sure it is not already initialized…

Do you have a clue on the way I can solve my problem ???

Many thanks in advance for your help 🙂

  • 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-20T19:50:09+00:00Added an answer on May 20, 2026 at 7:50 pm

    Even if I don’t need it anymore thanks to sudocode, I found a solution for my question. Maybe it could be useful for someone else…

    A collegue talked about the “antcallback” target of ant-contrib: it allows to return a result from a called target to the calling one. With a combination of “for” target and “antcallback” it is possible to do what I wanted to do:

    <target name="target">
        <taskdef resource="net/sf/antcontrib/antlib.xml" classpath="${lib.dir}/ant-contrib.jar"></taskdef>
        <for param="file">
            <path>
                <fileset dir="../myDirectory" includes="**/*" />
            </path>
            <sequential>
                <antcallback target="setVar" return="retValue">
                    <param name="file" value="@{file}"/>
                </antcallback>
            </sequential>
        </for>
        <echo>result: ${retValue}</echo>
    </target>
    <target name="setVar">
        <property name="retValue" value="${file}"/>
    </target>
    

    “file” contains the name of the file in the directory. It is given to the called target as parameter with value “@{file}” (‘@’ necessary due to “for” target implementation).

    At the end of the main target, ${retValue} contains the first value setted by the “setVar” target. No error is thrown when trying to set it multiple times, so it’s not necessary to check if variable has already been instantiated before to set it in “setVar” target.

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

Sidebar

Related Questions

Dear g++ hackers, I have the following question. When some data of an object
Dear all, I have a select query that currently produces the following results: DoctorName
Dear All, please help me since I'm newbie in SQL Server. I have a
dear all, i'll take some data from the database. and join two tables.the code
Dear experts, I am currently working on an code that allows users to drag
Dear all. I need to keep some temporary information in code. When i access
Dear folks, Currently a rewrite should redirect /index.php to /en/home And for that this
Dear Guys I have a simple wpf app with some local videos , my
Dear folks, Imagine a One Page Site RewriteCond %{HTTP_HOST} ^1pagesite.org$ RewriteRule ^$ 1pagesite.php [L]
Dear All, I'm using dojo.declare to create classes in JavaScript. In one of the

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.