ANT Tasks – Javac


Apache Ant Tasks – Javac



”;


Description

Javac task compiles a Java source tree. The source and destination directory will be recursively scanned for Java source files to compile. Only .java files that have no corresponding .class file or where the .class file is older than the .java file will be compiled.

Properties

















































Sr.No Attributes & Description
1

Srcdir

Location of the java files.

2

Destdir

Location to store the class files.

3

Includes

Comma- or space-separated list of patterns of files that must be included.

4

Includesfile

Name of a file. Each line of this file is taken to be an include pattern.

5

Excludes

Comma- or space-separated list of patterns of files that must be excluded.

6

Excludesfile

Name of a file. Each line of this file is taken to be an exclude pattern.

7

Defaultexcludes

Indicates whether default excludes should be used or not (yes|no).

8

Classpath

The classpath to use.

9

Sourcepath

The sourcepath to use. To suppress the sourcepath switch, use sourcepath=””.

10

Bootclasspath

Location of bootstrap class files.

11

Classpathref

The classpath to use, given as a reference to a path defined elsewhere.

12

Sourcepathref

The sourcepath to use, given as a reference to a path defined elsewhere.

13

Bootclasspathref

The bootstrapclasspath to use, given as a reference to a path defined elsewhere.

14

Extdirs

Location of installed extensions.

15

Encoding

Encoding of source files.

16

NSowarn

Indicates whether the -nowarn switch should be passed to the compiler.

17

Debug

Indicates whether source should be compiled with debug information. If set to off, -g:none will be passed on the command line for compilers that support it (for other compilers, no command line argument will be used). If set to true, the value of the debuglevel attribute determines the command line argument.

18

Debuglevel

Keyword list to be appended to the -g command-line switch. Legal values are none or a comma-separated list of the following keywords: lines, vars, and source.

19

Optimize

Indicates whether source should be compiled with optimization. Note that this flag is just ignored by Sun”s javac since JDK 1.3 (because compile-time optimization is unnecessary).

20

Deprecation

Indicates whether source should be compiled with deprecation information.

21

Verbose

Asks the compiler for verbose output.

22

Depend

Enables dependency tracking for compilers that support this (jikes and classic).

23

includeAntRuntime

Whether to include the Ant run-time libraries in the classpath. It is usually best to set this to false so the script”s behavior is not sensitive to the environment in which it is run.

24

includeJavaRuntime

Whether to include the default run-time libraries from the executing JVM in the classpath.

25

Fork

Whether to execute javac using the JDK compiler externally.

26

Executable

Complete path to the javac executable to use in case of fork is yes.

27

memoryInitialSize

The initial size of the memory for the underlying JVM, if javac is run externally. (Examples: 83886080, 81920k, or 80m)

28

memoryMaximumSize

The maximum size of the memory for the underlying JVM, if javac is run externally; ignored otherwise. (Examples: 83886080, 81920k, or 80m)

29

Failonerror

Indicates whether compilation errors will fail the build.

30

Errorproperty

The property to set to true if compilation fails.

31

Source

Java language features accepted by compiler, as specified by the -source command-line switch. Valid feature versions are 1.3, 1.4, 1.5 or 5, etc.

32

Target

Generate class files for specific JVM version (cross-compile).

33

Compiler

The compiler implementation to use.

34

listfiles

Indicates whether the source files to be compiled will be listed.

35

TempDir

Where Ant should place temporary files. This is only used if the task is forked and the command line args length exceeds 4 kB.

36

updatedProperty

The property to set to true if compilation has taken place and has been successful.

37

includeDestClasses

This attribute controls whether to include the destination classes directory in the classpath given to the compiler. If set to true (default), previously compiled classes are on the classpath for the compiler.

38

createMissingPackageInfoClass

Some package level annotations in package-info.java files don”t create any package-info.class files so Ant would recompile the same file every time.

39

MSodulepath

Specify where to find application modules. A list of directories of modules, module files or exploded modules.

40

Modulepathref

The modulepath to use, given as reference to a path defined elsewhere.

41

Modulesourcepath

Specify where to find input source files for multiple module compilation.

42

Modulesourcepathref

The modulesourcepath to use, given as reference to a path defined elsewhere.

43

Upgrademodulepath

Specify the location of modules that replace upgradeable modules in the runtime image.

44

Upgrademodulepathref

The upgrademodulepath to use, given as reference to a path defined elsewhere.

45

NSativeheaderdir

Specify where to place generated native header files.

46

Release

Specify the value for the –release switch. When set and running on JDK 9+ the source and target attributes as well as the bootclasspath will be ignored.

Example

Usage

Create TestMessage.java with the following content in src directory:


public class TestMessage {
   public static void main(String[] args) {
      System.out.println("Welcome to tutorialspoint.com");
   }
}

Create build.xml with the following content:


<?xml version="1.0"?>
<project name="TutorialPoint" default="info">
   <target name="info">      
      <javac srcdir="src" destdir="build"/>
   </target>
</project>

Above script will run a java class file to print output.

Output

Running Ant on the above build file produces the following output −


F:tutorialspointant>ant
Buildfile: F:tutorialspointantbuild.xml

info:
   [javac] F:tutorialspointantbuild.xml:4: warning: ''includeantruntime'' was not set, defaulting to build.sysclasspath=last; set to false for repeatable builds
   [javac] Compiling 1 source file to F:tutorialspointantbuild

BUILD SUCCESSFUL
Total time: 0 seconds

Advertisements

”;

Leave a Reply

Your email address will not be published. Required fields are marked *