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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T21:45:59+00:00 2026-05-12T21:45:59+00:00

What I’m trying to do is compile to a file which takes it’s version

  • 0

What I’m trying to do is compile to a file which takes it’s version from a constant inside my source files.

I have a setup like this (or at least the significant bits):

tasks/compile.xml

<project name="Compile">
    <target name="check.version">
        <script language="javascript">
            regex = /VERSION.+?"([\d\.]+)";/;
            r = new java.io.BufferedReader(new java.io.FileReader(new java.io.File(file)));
            line = r.readLine();
            while ( (line = r.readLine()) != null) {
                m = regex.exec(line);
                if (m) {
                    project.setProperty( "project.version" , m[1] );
                    break;
                }
            }
            r.close();
        </script>
        <echo>${ant.project.name}-${project.version}</echo> <!-- = Fail-0.2 -->
    </target>
</project>

And a build.xml:

<project name="Fail"> 
    <import file="${basedir}/build/tasks/compile.xml"/>

    <target name="test">
        <antcall target="check.version">
            <param name="file" value="${basedir}/Source.as"/>
        </antcall>
        <echo>${project.version}</echo> <!-- = ${project.version} -->
        <echoproperties></echoproperties>
    </target>
</project>

So, it seems that the property set by the script is only locally defined in that target, if i specify another target in the same project (“Compile”) it won’t know of that property either.

I’ve also tried to set a in the “Compile”-project xml but it won’t be overwritten by the target anyway.

So how can I access that property generated by the script? Or is there another way for doing something like this?

I’d really like to keep that part in a separate xml as it makes the project build script so much cleaner.

Thanks!

  • 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-12T21:45:59+00:00Added an answer on May 12, 2026 at 9:45 pm

    If you call the other target via antcall, properties set within it won’t be in the scope of the caller.

    If you need to access properties set by another target, you could declare that target as a dependency to ensure that it gets executed before your target. Like this:

    <target name="test" depends="check.version">
        <echo>${project.version}</echo> <!-- = value set in check.version -->
        <echoproperties></echoproperties>
    </target>
    

    Edit: There’s also the AntCallBack task which is available from Ant-Contrib and Antelope:

    AntCallBack is identical to the
    standard ‘antcall’ task, except that
    it allows properties set in the called
    target to be available in the calling
    target.

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

Sidebar

Related Questions

No related questions found

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.