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"/>
To include only specific files from a folder in your
javaccompilation 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)
Java Source Files
Class1.java
Class2.java
Class3.java
Ant Output
Ant target compile_class1
Notice that although there were three Java source files, only the file specified by the
<include>element was compiled.Ant target compile_class2
In this case, although the Ant target
compile_class2only 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.