NAME
javac - Java compiler
SYNOPSIS
jjaavvaacc [ options ] [ sourcefiles ] [ @@argfiles ] PPAARRAAMMEETTEERRSS Arguments may be in any order. options Command line options. sourcefiles One or more source files to be compiled (such as MMyyCCllaassss..jjaavvaa).@@argfiles One or more files that list source files. The -J
options are not allowed in these files.DESCRIPTION
The jjaavvaacc tool reads class and interface definitions, written in the Java programming language, and compiles them into bytecode class files. There are two ways to pass source code file names to jjaavvaacc: +o For a small number of source files, simply list the file names on the command line. +o For a large number of source files, list the file names in a file, separated by blanks or line breaks. Then use the list file name on the jjaavvaacc command line, preceded by an @ character. Source code file names must have ..jjaavvaa suffixes, class file names must have ..ccllaassss suffixes, and both source and class files must have root names that identify the class. For example, a class called MMyyCCllaassss would be written in a source file called MMyyCCllaassss..jjaavvaa and compiled into a bytecode class file called MMyyCCllaassss..ccllaassss. Inner class definitions produce additional class files. These class files have names combining the inner and outer class names, such asMMyyCCllaassss$$MMyyIInnnneerrCCllaassss..ccllaassss.
You should arrange source files in a directory tree that reflects their package tree. For example, if you keep all your source files in //wwoorrkkssppaaccee, the source code for ccoomm..mmyyssoofftt..mmyyppaacckk..MMyyCCllaassss should be in //wwoorrkkssppaaccee//ccoomm//mmyyssoofftt//mmyyppaacckk//MMyyCCllaassss..jjaavvaa. By default, the compiler puts each class file in the same directory as its source file. You can specify a separate destination directory with-dd (see OOPPTTIIOONNSS, below).
SSeeaarrcchhiinngg ffoorr TTyyppeess When compiling a source file, the compiler often needs information about a type whose definition did not appear in the source files given on the command line. The compiler needs type information for every class or interface used, extended, or implemented in the source file. This includes classes and interfaces not explicitly mentioned in the source file but which provide information through inheritance. For example, when you subclass jjaavvaa..aapppplleett..AApppplleett, you are also using Applet's ancestor classes: jjaavvaa..aawwtt..PPaanneell, jjaavvaa..aawwtt..CCoonnttaaiinneerr, jjaavvaa..aawwtt..CCoommppoonneenntt, and jjaavvaa..aawwtt..OObbjjeecctt. When the compiler needs type information, it looks for a source file or class file which defines the type. The compiler searches first in the bootstrap and extension classes, then in the user class path (which by default is the current directory). The user class path is defined bysetting the CCLLAASSSSPPAATTHH environment variable or by using the -ccllaassssppaatthh
command line option. (For details, see SSeettttiinngg tthhee CCllaassss PPaatthh.)If you use the -ssoouurrcceeppaatthh option, the compiler searches the indicated
path for source files; otherwise the compiler searches the user class path both for class files and source files. You can specify differentbootstrap or extension classes with the -bboooottccllaassssppaatthh and -eexxttddiirrss
pin; e Cross-Compilation Options eo.
A successful type search may produce a class file, a source file, or both. Here is how jjaavvaacc handles each situation: +o Search produces a class file but no source file: jjaavvaacc uses the class file. +o Search produces a source file but no class file: jjaavvaacc compiles the source file and uses the resulting class file. +o Search produces both a source file and a class file: jjaavvaacc determines whether the class file is out of date. If the class file is out of date, jjaavvaacc recompiles the source file and uses the updated class file. Otherwise, jjaavvaacc just uses the class file. By default, jjaavvaacc considers a class file out of date only if it is older than the source file.Note: jjaavvaacc can silently compile source files not mentioned on the com-
mand line. Use the -vveerrbboossee option to trace automatic compilation.
OOPPTTIIOONNSS The compiler has a set of standard options that are supported on the current development environment and will be supported in futurereleases. An additional set of non-standard options are specific to
the current virtual machine implementation and are subject to change inthe future. Non-standard options begin with -XX.
Standard Options-ccllaassssppaatthh classpath
Sets the user class path, overriding the user class path in theCCLLAASSSSPPAATTHH environment variable. If neither CCLLAASSSSPPAATTHH or -ccllaassss-
ppaatthh is specified, the user class path consists of the current directory. See SSeettttiinngg tthhee CCllaassss PPaatthh for more details.If the -ssoouurrcceeppaatthh option is not specified, the user class path
is searched for both source files and class files.-DDjjaavvaa..eexxtt..ddiirrss==directories
Override the location of installed extensions.-DDjjaavvaa..eennddoorrsseedd..ddiirrss==directories
Override the location of endorsed standards path.-dd directory
Sets the destination directory for class files. The destinationdirectory must already exist; javac will not create the destina-
tion directory. If a class is part of a package, jjaavvaacc puts theclass file in a subdirectory reflecting the package name, creat-
ing directories as needed. For example, if you specify -dd
//hhoommee//mmyyccllaasssseess and the class is called ccoomm..mmyyppaacckkaaggee..MMyyCCllaassss,then the class file is called //hhoommee//mmyyccllaasssseess//ccoomm//mmyyppaacckk-
aaggee//MMyyCCllaassss..ccllaassss.If -dd is not specified, jjaavvaacc puts the class file in the same
directory as the source file.Note: The directory specified by -dd is not automatically added
to your user class path.-ddeepprreeccaattiioonn
Shows a description of each use or override of a deprecated mem-
ber or class. Without -ddeepprreeccaattiioonn, jjaavvaacc shows the names of
source files that use or override deprecated members or classes.-deprecation is shorthand for -XXlliinntt::ddeepprreeccaattiioonn.
-eennccooddiinngg encoding
Sets the source file encoding name, such asEUCJIS/SJIS/ISO8859-1/UTF8. If -eennccooddiinngg is not specified, the
platform default converter is used.-gg Generates all debugging information, including local variables.
By default, only line number and source file information is gen-
erated.-gg::nnoonnee
Does not generate any debugging information.-gg::keyword-list
Generates only some kinds of debugging information, specified by a comma separated list of keywords. Valid keywords are: ssoouurrccee Source file debugging information lliinneess Line number debugging information vvaarrss Local variable debugging information-hheellpp Prints a synopsis of standard options.
-nnoowwaarrnn
Disables warning messages. This has the same meaning as-XXlliinntt::nnoonnee.
-ssoouurrccee release
Enables support for compiling source code containing assertions. The following values for release are allowed: 1.5 The compiler accepts code containing generics and other language features introduced in JDK 1.5. The compilerdefaults to the 1.5 behavior if the -source flag is not
used. 5 Synonym for 1.5 1.4 The compiler accepts code containing assertions, which were introduced in JDK 1.4. 1.3 The compiler does not support assertions, generics, or other language features introduced after JDK 1.3.-ssoouurrcceeppaatthh sourcepath
Specify the source code path to search for class or interface definitions. As with the user class path, source path entriesare separated by colons (::) and can be directories, JAR ar-
chives, or ZIP archives. If packages are used, the local path name within the directory or archive must reflect the package name.Note: Classes found through the classpath are subject to auto-
matic recompilation if their sources are found.-vveerrbboossee
Verbose output. This includes information about each class loaded and each source file compiled.-XX Display information about non-standard options and exit.
CrossCompilation Options By default, classes are compiled against the bootstrap and extension classes of the JDK that jjaavvaacc shipped with. But jjaavvaacc also supportscross-compiling, where classes are compiled against a bootstrap and
extension classes of a different Java platform implementation. It isimportant to use -bboooottccllaassssppaatthh and -eexxttddiirrss when cross-compiling; see
CCrroossss-CCoommppiillaattiioonn EExxaammppllee below.
-ttaarrggeett version
Generates class files that will work on VMs with the specifiedversion. The default is to generate class files to be compati-
ble with 1.2 VMs, with one exception. When the -ssoouurrccee 1.4
option is used, the default target is 1.4. The versions sup-
ported by jjaavvaacc are: 1.1 Ensures that generated class files will be compatible with 1.1 and later. VMs. 1.2 Generates class files that will run on 1.2 and later VMs, but will not run on 1.1 VMs. 1.3 Generates class files that run on VMs in the Java 2 SDK, v1.3 and later, but will not run on 1.1 or 1.2 VMs. 1.4 Generates class files that will run on VMs in JDK 1.4 and later, but will not run on 1.1, 1.2, or 1.3 VMs. 1.5 Generate class files that are compatible only with JDK 1.5 VMs. 5 Synonym for 1.5-bboooottccllaassssppaatthh bootclasspath
Cross-compiles against the specified set of boot classes. As
with the user class path, boot class path entries are separatedby colons (::) and can be directories, JAR archives, or ZIP ar-
chives.-ccllddcc11..00
Use to compile CLDC programs. The compiler generates stack maps making the use of the preverifier unnecessary.-eexxttddiirrss directories
Cross-compiles against the specified extension directories.
directories are a colon-separated list of directories. Each JAR
archive in the specified directories is searched for class files. NonStandard Options-XXbboooottccllaassssppaatthh//pp::path
Prepend to the bootstrap class path.--XXbboooottccllaassssppaatthh//aa::path
Append to the bootstrap class path.-XXbboooottccllaassssppaatthh//::path
Override location of bootstrap class files.-XXlliinntt Enable all recommended warnings. In this release, all available
warnings are recommended.-XXlliinntt::nnoonnee
Disable all warnings not mandated by the Java Language Specifi-
cation.-XXlliinntt::-xxx
Disable warning xxx, where xxx is one of the warning names sup-
ported for -XXlliinntt::xxx, below.
-XXlliinntt::uunncchheecckkeedd
Give more detail for unchecked conversion warnings that are man-
dated by the Java Language Specification.-XXlliinntt::ppaatthh
Warn about nonexistent path (classpath, sourcepath, etc) direc-
tories.-XXlliinntt::sseerriiaall
Warn about missing serialVersionUID definitions on serializable classes.-XXlliinntt::ffiinnaallllyy
Warn about finally clauses that cannot complete normally.-XXlliinntt::ffaalllltthhrroouugghh
Check switch blocks for fall-through cases and provide a warning
message for any that are found. Fall-through cases are cases in
a switch block, other than the last case in the block, whose code does not include a break statement, allowing code execution to "fall through" from that case to the next case. For example, the code following the case 1 label in this switch block does not contain a break statement: sswwiittcchh ((xx)) {{ ccaassee 11:: SSyysstteemm..oouutt..pprriinnttllnn((""11""));; //// NNoo bbrreeaakk;; ssttaatteemmeenntt hheerree.. ccaassee 22:: SSyysstteemm..oouutt..pprriinnttllnn((""22""));; }}If the -XXlliinntt::ffaalllltthhrroouugghh flag were used when compiling this code, the
compiler would emit a warning about "possible fall-through into case,"
along with the line number of the case in question.-XXmmaaxxeerrrroorrss number
Set the maximum number of errors to print.-XXmmaaxxwwaarrnnss number
Set the maximum number of warnings to print.-XXssttddoouutt filename
Send compiler messages to the named file. By default, compiler messages go to SSyysstteemm..eerrrr.TTHHEE -JJ OOPPTTIIOONN
-JJoption
Pass option to the java launcher called by jjaavvaacc. For example,-JJ-XXmmss4488mm sets the startup memory to 48 megabytes. Although it
does not begin with -XX, it is not a `standard option' of jjaavvaacc.
It is a common convention for -JJ to pass options to the underly-
ing VM executing applications written in Java.Note: CCLLAASSSSPPAATTHH, -ccllaassssppaatthh, -bboooottccllaassssppaatthh, and -eexxttddiirrss do not spec-
ify the classes used to run jjaavvaacc. Fiddling with the implementation of the compiler in this way is usually pointless and always risky. If youdo need to do this, use the -JJ option to pass through options to the
underlying java launcher. COMMAND LINE ARGUMENT FILES To shorten or simplify the jjaavvaacc command line, you can specify one or more files that themselves contain arguments to the jjaavvaacc command. This enables you to create jjaavvaacc commands of any length on any operating system. An argument file can include jjaavvaacc options and source filenames in anycombination. The arguments within a file can be space-separated or
newline-separated. Filenames within an argument file are relative to
the current directory, not the location of the argument file. Wild-
cards (*) are not allowed in these lists (such as for specifying **..jjaavvaa). Use of the @@ character to recursively interpret files is not supported. When executing jjaavvaacc, pass in the path and name of each argument filewith the @@ leading character. When jjaavvaacc encounters an argument begin-
ning with the character @@, it expands the contents of that file into the argument list.EExxaammppllee - SSiinnggllee AArrgg FFiillee
You could use a single argument file named aarrggffiillee to hold all javac
arguments:%% jjaavvaacc @@aarrggffiillee
This argument file could contain the contents of both files shown in the next example.EExxaammppllee - TTwwoo AArrgg FFiilleess
You can create two argument files - one for the jjaavvaacc options and the
other for the source filenames: (Notice the following lists have noline-continuation characters.)
Create a file named ooppttiioonnss containing:-dd ccllaasssseess
-gg
-ssoouurrcceeppaatthh //jjaavvaa//ppuubbss//wwss//11..33//ssrrcc//sshhaarree//ccllaasssseess
Create a file named ccllaasssseess containing: MMyyCCllaassss11..jjaavvaa MMyyCCllaassss22..jjaavvaa MMyyCCllaassss33..jjaavvaa You would then run jjaavvaacc with:%% jjaavvaacc @@ooppttiioonnss @@ccllaasssseess
EExxaammppllee - AArrgg FFiilleess wwiitthh PPaatthhss
The argument files can have paths, but any filenames inside the files are relative to the current working directory (not ppaatthh11 or ppaatthh22):%% jjaavvaacc @@ppaatthh11//ooppttiioonnss @@ppaatthh22//ccllaasssseess
EEXXAAMMPPLLEESS CCoommppiilliinngg aa SSiimmppllee PPrrooggrraamm One source file, HHeelllloo..jjaavvaa, defines a class called ggrreeeettiinnggss..HHeelllloo. The greetings directory is the package directory both for the source file and the class file and is off the current directory. This allows us to use the default user class path. It also makes it unnecessary tospecify a separate destination directory with -dd.
%% llss
ggrreeeettiinnggss//%% llss ggrreeeettiinnggss
HHeelllloo..jjaavvaa%% ccaatt ggrreeeettiinnggss//HHeelllloo..jjaavvaa
ppaacckkaaggee ggrreeeettiinnggss;; ppuubblliicc ccllaassss HHeelllloo {{ ppuubblliicc ssttaattiicc vvooiidd mmaaiinn((SSttrriinngg[[]] aarrggss)) {{ ffoorr ((iinntt ii==00;; ii << aarrggss..lleennggtthh;; ii++++)) {{ SSyysstteemm..oouutt..pprriinnttllnn((""HHeelllloo "" ++ aarrggss[[ii]]));; }} }} }}%% jjaavvaacc ggrreeeettiinnggss//HHeelllloo..jjaavvaa
%% llss ggrreeeettiinnggss
HHeelllloo..ccllaassss HHeelllloo..jjaavvaa%% jjaavvaa ggrreeeettiinnggss..HHeelllloo WWoorrlldd UUnniivveerrssee EEvveerryyoonnee
HHeelllloo WWoorrlldd HHeelllloo UUnniivveerrssee HHeelllloo EEvveerryyoonnee CCoommppiilliinngg MMuullttiippllee SSoouurrccee FFiilleess This example compiles all the source files in the package greetings.%% llss
ggrreeeettiinnggss//%% llss ggrreeeettiinnggss
AAlloohhaa..jjaavvaa GGuutteennTTaagg..jjaavvaa HHeelllloo..jjaavvaa HHii..jjaavvaa%% jjaavvaacc ggrreeeettiinnggss//**..jjaavvaa
%% llss ggrreeeettiinnggss
AAlloohhaa..ccllaassss GGuutteennTTaagg..ccllaassss HHeelllloo..ccllaassss HHii..ccllaassss AAlloohhaa..jjaavvaa GGuutteennTTaagg..jjaavvaa HHeelllloo..jjaavvaa HHii..jjaavvaa SSppeecciiffyyiinngg aa UUsseerr CCllaassss PPaatthh Having changed one of the source files in the previous example, we recompile it:%% ppwwdd
//eexxaammpplleess%% jjaavvaacc ggrreeeettiinnggss//HHii..jjaavvaa
Since the class ggrreeeettiinnggss..HHii refers to other classes in the greetings package, the compiler needs to find these other classes. The example above works, because our default user class path happens to be the directory containing the package directory. But suppose we want to recompile this file and not worry about which directory we're in? Then we need to add //eexxaammpplleess to the user class path. We can do this bysetting CCLLAASSSSPPAATTHH, but here we'll use the -ccllaassssppaatthh option.
%% jjaavvaacc -ccllaassssppaatthh //eexxaammpplleess //eexxaammpplleess//ggrreeeettiinnggss//HHii..jjaavvaa
If we change ggrreeeettiinnggss..HHii again, to use a banner utility, that utility also needs to be accessible through the user class path.%% jjaavvaacc -ccllaassssppaatthh //eexxaammpplleess:://lliibb//BBaannnneerrss..jjaarr //eexxaammpplleess//ggrreeeettiinnggss//HHii..jjaavvaa
To execute a class in greetings, we need access both to greetings and to the classes it uses.%% jjaavvaa -ccllaassssppaatthh //eexxaammpplleess:://lliibb//BBaannnneerrss..jjaarr ggrreeeettiinnggss..HHii
SSeeppaarraattiinngg SSoouurrccee FFiilleess aanndd CCllaassss FFiilleess It often makes sense to keep source files and class files in separatedirectories, especially on large projects. We use -dd to indicate the
separate class file destination. Since the source files are not in theuser class path, we use -ssoouurrcceeppaatthh to help the compiler find them.
%% llss
ccllaasssseess// lliibb// ssrrcc//%% llss ssrrcc
ffaarreewweellllss//%% llss ssrrcc//ffaarreewweellllss
BBaassee..jjaavvaa GGooooddBByyee..jjaavvaa%% llss lliibb
BBaannnneerrss..jjaarr%% llss ccllaasssseess
%% jjaavvaacc -ssoouurrcceeppaatthh ssrrcc -ccllaassssppaatthh ccllaasssseess::lliibb//BBaannnneerrss..jjaarr \\
ssrrcc//ffaarreewweellllss//GGooooddBByyee..jjaavvaa -dd ccllaasssseess
%% llss ccllaasssseess
ffaarreewweellllss//%% llss ccllaasssseess//ffaarreewweellllss
BBaassee..ccllaassss GGooooddBByyee..ccllaassss Note: The compiler compiled src/farewells/Base.java, even though we didn't specify it on the command line. To trace automatic compiles,use the -vveerrbboossee option.
CCrroossss-CCoommppiillaattiioonn EExxaammppllee
Here we use jjaavvaacc to compile code that will run on a 1.4 VM.%% jjaavvaacc -ttaarrggeett 11..44 -bboooottccllaassssppaatthh jjddkk11..44..22//lliibb//ccllaasssseess..zziipp \\
-eexxttddiirrss """" OOllddCCooddee..jjaavvaa
The -ttaarrggeett 11..44 option ensures that the generated class files will be
compatible with 1.4 VMs. BY default, jjaavvaacc compiles for 1.5. The Java 2 SDk's jjaavvaacc would also by default compile against its own bootstrap classes, so we need to tell jjaavvaacc to compile against JDK 1.4bootstrap classes instead. We do this with -bboooottccllaassssppaatthh and
-eexxttddiirrss. Failing to do this might allow compilation against a Java 2
Platform API that would not be present on a 1.4 VM and would fail at runtime.SEE ALSO
jjaarr(1), jjaavvaa(1), jjaavvaaddoocc(1), jjaavvaahh(1), jjaavvaapp(1), jjddbb(1) See or search the Java web site for the following: The Java Extensions Mechanism @ http://java.sun.com/j2se/1.5/docs/guide/extensions/index.html05 March 2002 javac(1)