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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T06:16:08+00:00 2026-05-26T06:16:08+00:00

I want to extract the version number from a file name generated outside of

  • 0

I want to extract the version number from a file name generated outside of my Ant script.

An external build tool (PDE build) creates a file of the form artifactid-1.2.3.201101010101.jar in a well-known directory, but I can not tell the versioning information beforehand. I need to extract the version part (1.2.3.201101010101) from that file name into an Ant property for further processing, e.g. variable substitution.

Using ant-contrib is acceptable, however I have not found a way to extract this information.

  • 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-26T06:16:09+00:00Added an answer on May 26, 2026 at 6:16 am

    Here’s a solution using the ant-contrib PropertyRegex task.

    • Get the filename into a path.
    • Convert the path to a property.
    • PropertyRegex the property (ant-contrib).

    You could avoid ant-contrib by writing the property value to a temporary file and then using loadfile with a filterchain to extract the artifact id from it. See this answer for an example.

      <project default="get-revision-number">
            <taskdef resource="net/sf/antcontrib/antcontrib.properties">
                    <classpath>
                            <pathelement location="c:/lib/ant-contrib/ant-contrib-1.0b3.jar"/>
                    </classpath>
            </taskdef>
    
            <target name="get-revision-number">
                    <path id="artifact.id.path">
                            <fileset dir=".">
                                    <include name="artifactid-*.jar"/>
                            </fileset>
                    </path>
                    <property name="artifact.id.file" refid="artifact.id.path"/>
                    <echo message="artifact.id.file: ${artifact.id.file}"/>
                    <propertyregex property="artifact.id" input="${artifact.id.file}" regexp=".*artifactid-(.*).jar" select="\1" />
                    <echo message="artifact.id: ${artifact.id}"/>
            </target>
      </project>
    

    Output

    $ ant
    Buildfile: C:\tmp\build.xml
    
    get-revision-number:
         [echo] artifact.id.file: C:\tmp\artifactid-1.2.3.201101010101.jar
         [echo] artifact.id: 1.2.3.201101010101
    
    BUILD SUCCESSFUL
    Total time: 0 seconds
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to extract version number from string. a string = Tale: The Secrets
I want to achieve the same as explained in sed: Extract version number from
I want to extract just the file name portion of a path. My code
Is there a clean way to extract the version string from a .gemspec file?
I want to extract all the properties from my pom.xml into a properties-file. These
I want to extract a copy of the latest version of a file held
I want to extract a file from a zip to a specific path, ignoring
I want to extract from a webpage all URLs how can I do that
I want to extract two consecutive words starting from each word in a string.
I want to extract only the leaf nodes from an XML document (i.e., only

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.