Javatpoint Logo
Javatpoint Logo

Apache Ant Javac Task

Ant Javac task is used to compile Java source file. It scans source and destination directory to compile the source file. It only compiles if either .class is not present or .class is older than Java file.

If the Java source file is located into any package, source file should have directory hierarchy.

Apache Ant Javac Attributes

Attribute Description Required
srcdir Source Java file. Yes
destdir Destination to store the class files. No
includes A list of patterns of files that must be included. No
includesfile Each line of this file is taken to be an include pattern. No
excludes A list of patterns of files that must be excluded. No; defaults to default excludes or none if defaultexcludes is no
excludesfile Each line of this file is taken to be an exclude pattern. No
classpath The classpath to use. No
bootclasspath Path of bootstrap class files. No
extdirs Path of installed extensions. No
encoding Encoding of source files. No
nowarn It is used to pass -nowarn switch to the compiler. No
debug To debug file during compilation. No
debuglevel Set level of debug file. No
optimize Indicates whether source should be compiled with optimization. No
deprecation Compile with with deprecation information. No
verbose Asks the compiler for verbose output. No
depend Enables dependency tracking for compilers that support it. No
includeAntRuntime Whether to include the Ant run-time libraries in the classpath or not. No
fork Whether to execute javac using the JDK compiler externally or not. No
executable Complete path to the javac executable. No
memoryInitialSize Set initial memory size. No
memoryMaximumSize The maximum size of the memory for the underlying JVM. No

Apache Ant Javac Example

The following code compiles a Java source file and store class file into destination directory.

// build.xml

Example: Setting debug mode true

This example will compile all Java source file located into srcdir and store .class into destdir directory. It will compile Java source in debug mode because the debug mode is on.

Example : Setting source level and target version

This example will compile all Java source file located into srcdir and store .class into destdir directory. The source level is 1.8 and the .class file will run under Jdk 1.8.





Help Others, Please Share

facebook twitter google plus pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA