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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T14:03:22+00:00 2026-06-08T14:03:22+00:00

I want to write the Ant script that excludes the complete folder except some

  • 0

I want to write the Ant script that excludes the complete folder except some of the files.

I have one folder where thousands of Java files are located. Now I want to exclude that folder and I want to include two Java files out of that. How can I do that?

The below code doesn’t work for me.

<target  name="compile" >
    <javac srcdir="src" destdir="./classes"
        <exclude name="com/corporate/modes/**"/>
        <include name="com/corporate/modes/UpdatePersonalDetail.java"/>
  • 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-08T14:03:23+00:00Added an answer on June 8, 2026 at 2:03 pm

    To include only specific files from a folder in your javac compilation task, specify the files using the <include> element. When an <include> element is specified, only the named file (and its project dependencies) will be included in the compilation.

    Example Project

    Project Directory: /home/project
    Source Directory: /home/project/src
    Build Directory: /home/project/build


    build.xml (located in /home/project)

    <?xml version="1.0" encoding="UTF-8"?>
    <project name="compile_test" basedir="." default="compile_class1">
    
      <property name="src.dir" value="${basedir}/src" />
      <property name="build.dir" location="${basedir}/build" />
      <property name="classes.dir" location="${build.dir}/classes" />
    
      <target name="init" description="Initialize the build directory.">
        <mkdir dir="${build.dir}" />
        <mkdir dir="${classes.dir}" />
      </target>
    
      <target name="clean" description="Delete all files created by this script.">
        <delete dir="${build.dir}" />
      </target>
    
      <target name="compile_class1" depends="init">
        <javac srcdir="${src.dir}" destdir="${classes.dir}"
            includeantruntime="false">
          <include name="com/mypackage/Class1.java" />
        </javac>
      </target>
    
      <target name="compile_class2" depends="init">
        <javac srcdir="${src.dir}" destdir="${classes.dir}"
            includeantruntime="false">
          <include name="com/mypackage/Class2.java" />
        </javac>
      </target>
    </project>
    

    Java Source Files

    Class1.java

    package com.mypackage;
    
    public class Class1 {
      public static void main(String[] args){
        System.out.println("Class1");
      }
    }
    

    Class2.java

    package com.mypackage;
    
    public class Class2 {
      public static void main(String[] args){
        Class3 class3 = new Class3();
        System.out.println(class3.getMessage());
      }
    }
    

    Class3.java

    package com.mypackage;
    
    public class Class3 {
      public String getMessage() {
        return "The answer is 42.";
      }
    }
    

    Ant Output

    Ant target compile_class1

    $ ant clean compile_class1
    
    Buildfile: /home/project/build.xml
    
    clean:
       [delete] Deleting directory /home/project/build
    
    init:
        [mkdir] Created dir: /home/project/build
        [mkdir] Created dir: /home/project/build/classes
    
    compile_class1:
        [javac] Compiling 1 source file to /home/project/build/classes
    
    BUILD SUCCESSFUL
    Total time: 1 second
    

    Notice that although there were three Java source files, only the file specified by the <include> element was compiled.


    Ant target compile_class2

    $ ant clean compile_class2
    
    Buildfile: /home/project/build.xml
    
    clean:
       [delete] Deleting directory /home/project/build
    
    init:
        [mkdir] Created dir: /home/project/build
        [mkdir] Created dir: /home/project/build/classes
    
    compile_class2:
        [javac] Compiling 1 source file to /home/project/build/classes
    
    BUILD SUCCESSFUL
    Total time: 1 second
    

    In this case, although the Ant target compile_class2 only specified one file in the nested <include> element, both Class2.java and Class3.java were compiled since Class2.java depends on Class3.java. If the dependencies of Class2.java were not included in the compilation, then when attempting to execute Class2, you would receive an error that com.mypackage.Class3 could not be located.

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

Sidebar

Related Questions

I have an ant build system. I have some common build files (common.xml) that
I'm new to J2ME application development, I want to write an ANT script to
Can anyone tell me how to write Ant script (if i want to create
I want to write an ant macro that will call the fail task if
Question We have a large number of xml configuration files that we want merged
I have two XML examples that I want to write a schema for: Example
I want to copy some files with Rake, but compared to Ant this is
I have a simple syntax for script files of a given extension that translates
Hello I want write my own desktop sharing application in Java. The application should
I want to write a batch script statement where: FINDSTR has to check for

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.