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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T04:25:11+00:00 2026-06-03T04:25:11+00:00

Hi i am trying to build an ant script that copies a certain lib

  • 0

Hi i am trying to build an ant script that copies a certain lib file based on a if condition. however it doesnt seem to work as i get this error:

build.xml:20: fileset doesn’t support the nested “if” element.

this is the part where it fails:

<target name="resolve">
        <delete dir="${lib.dir}">
            <include name="*" />
        </delete>

        <copy todir="${lib.dir}">
            <fileset dir="ext-libs" >
                <if name="${release}" value="true">
                    <include name="hello-client-[^DEBUG]*.jar" />
                </if>
                <else>
                    <include name="hello-client-*DEBUG.*.jar" />
                </else>

            </fileset>
        </copy>
    </target>
  • 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-03T04:25:13+00:00Added an answer on June 3, 2026 at 4:25 am

    @JoseK is right. ANT filesets do not support nested “if” statements. In fact the “if” statement is not part of core ANT the recommended approach is to use conditional targets (See example)

    @slipset is on the right track. Ivy configurations can be used to selectively choose your dependencies.

    Example

    This example is designed to be invoked in one of two ways

    $ ant clean build
    $ tree
    .
    |-- build.xml
    |-- ivy.xml
    `-- lib
        |-- slf4j-api-1.6.4.jar
        `-- slf4j-simple-1.6.4.jar
    

    Or

    $ ant -Drelease=1 clean build
    $ tree
    .
    |-- build.xml
    |-- ivy.xml
    `-- lib
        |-- logback-classic-1.0.3.jar
        |-- logback-core-1.0.3.jar
        `-- slf4j-api-1.6.4.jar
    

    build.xml

    <project name="demo" default="build" xmlns:ivy="antlib:org.apache.ivy.ant">
    
        <target name="resolve">
            <ivy:resolve/>
        </target>
    
        <target name="retrieve-alt" depends="resolve" unless="release">
            <ivy:retrieve pattern="lib/[artifact]-[revision](-[classifier]).[ext]" conf="altruntime"/>
        </target>
    
        <target name="retrieve-release" depends="resolve" if="release">
            <ivy:retrieve pattern="lib/[artifact]-[revision](-[classifier]).[ext]" conf="runtime"/>
        </target>
    
        <target name="build" depends="retrieve-alt,retrieve-release"/>
    
        <target name="clean">
            <delete dir="lib"/>
        </target>
    
    </project>
    

    Notes:

    • The if and unless clauses on the targets perform a conditional test on the existence of the “release” property.
    • The ivy retrieve task uses a configuration to decide which jars should be used to populate the “lib” directory.
    • The retrieve pattern includes a “classifier” pattern, just in case you ivy mapping pulls down additional Maven artifacts like the source or javadoc jars.

    ivy.xml

    <ivy-module version="2.0">
        <info organisation="com.myspotontheweb" module="demo"/>
    
        <configurations>
            <conf name="compile" description="Required to compile application"/>
            <conf name="runtime" description="Additional run-time dependencies" extends="compile"/>
            <conf name="altruntime"   description="Alternative 'runtime' configuration" extends="compile"/>
            <conf name="test"    description="Required for test only" extends="altruntime"/>
        </configurations>
    
        <dependencies>
            <!-- compile dependencies -->
            <dependency org="org.slf4j" name="slf4j-api" rev="1.6.4" conf="compile->default"/>
    
            <!-- runtime dependencies -->
            <dependency org="ch.qos.logback" name="logback-classic" rev="1.0.3" conf="runtime->default"/>
    
            <!-- altruntime dependencies -->
            <dependency org="org.slf4j" name="slf4j-simple" rev="1.6.4" conf="altruntime->default"/>
    
            <!-- test dependencies -->
            <dependency org="junit" name="junit" rev="4.10" conf="test->default"/>
        </dependencies>
    
    </ivy-module>
    

    Note:

    • I would highly recommend always specifying a configuration mapping for each dependency. This will then map directly to how you intend to use the jars, for example populate a classpath.

    Appendix

    How to use ivy configurations

    Ivy configurations can be used to emulate Maven scopes, but in fact an ivy configuration can represent any logical grouping of dependencies.

    Here are the 3 standard classpaths required in any Java build:

    <configurations>
        <conf name="compile" description="Required to compile application"/>
        <conf name="runtime" description="Additional run-time dependencies" extends="compile"/>
        <conf name="test"    description="Required for test only" extends="runtime"/>
    </configurations>
    

    Note the “extends” syntax that enables you to create larger sets. For example, the runtime set of jars also includes anything needed to compile the code your code.

    Ivy configurations are difficult to understand until you realise that they can be used to selectively populate an ANT path:

    <ivy:cachepath pathid="compile.path" conf="compile"/>
    
    <javac ..... classpathref="compile.path"/>
    

    Or used to selectively populate a directory

    <ivy:retrieve pattern="build/WEB-INF/lib/[artifact].[ext]" conf="runtime"/>
    

    Configuration mappings

    Mappings are used to decide how groups of jars in your project relate to groups of jars in other projects.

    This normally happens as follows:

    <dependency org="org.slf4j" name="slf4j-api" rev="1.6.4" conf="compile->default"/>
    

    Here our compile configuration is populate by the remote default configuration (normally the other modules compile dependencies)

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

Sidebar

Related Questions

Greeting, I'm trying to put some Beanshell script in my Ant build.xml file. I've
I am trying to run an ant build script that compiles GWT. This script
I'm trying to run a script that uses an ANT build but I don't
I am trying to build subprojects from my main Ant build script.. The build
I am new to ant, but am trying to create an ant script that
I am trying to check the ant build script's argument is set or not.
I'm trying to integrate emma with an ant build, that does junit testing. My
I have a build script and as part of that script it copies a
In trying to build a ant script for my Flex project i've come across
I'm trying to write an ant build script to build my group's flex app,

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.