Command Line Options


Compiling code: In-depth

There are lots of options that you can use while compiling a program file. These are called the command-line directives that you can use with javac. The javac tool can generally be used in the following format:
                javac [options] [sourcefiles] [@files]
·         options –     Command line options. We’ll be discussing them soon
·         sourcefiles – The sourcefiles (.java files) to be compiled (Can be more than one)
·         @files –      One or more files that list source files

The various command-line options available for use with javac are:
Ø  -classpath
It sets the user class path by overriding the path set in the CLASSPATH environment variable. If neither –classpath nor CLASSPATH is specified, the user class path is the current directory. Remember, if the –sourcepath option is not used or specified, the compiler will look for the source files as well as the class files in the user class path.   
Ø  -d
It is used to specify the directory where you want your class files to be stored. If you don’t use this option the class files will be put in the same directory as that of the source files.
Ø  -deprecation
It shows a description of the deprecated methods or members or class that you’ve used or overridden in your program.
Ø  -encoding
It sets the source file encoding name. If not used, the compiler uses the default platform converter.
Ø  -g
It generates all debugging information. By default, it generates only line number and source file information. It can also generate local variables information.
Ø  -g:none
It disables all debugging information.
Ø  -g:{keyword list}
It limits the debugging information produced to the ones specified by the keyword list. The valid keywords include: source (source file debugging information), lines (line number debugging information), vars (local variable debugging information).
Ø  -nowarn
It makes the compiler not generate any warning messages.
Ø  -O
It optimizes code for performance in terms of execution time. However, this results in slower compile time, larger class files and also makes the program difficult to debug.
Ø  -sourcepath
It specifies the path to search for your source code files. The path can be directories, .jar (Java Archive) files or zip files. If you use packages, the local pathname within the directory or archive must reflect the package name. For example, if you have a class geometry.shapes.Rectangle’, geometry and shapes being the package and sub-package respectively, the path should be something like geometry\shapes\’.
Ø  -verbose
This creates a detailed or “verbose” output, which includes information about each class loaded and each source file compiled.
Ø  -X
It displays information about non-standard options and quits.
Ø  -Xdepend
It searches for all source file dependencies and recompiles them. This slows down the compiling process dramatically.
Ø  -Xstdout
Generally, all compile-time messages are printed through System.err (Java Error Stream). If you use this option, the compile-time messages will be directed to System.out (java Output Stream).
Ø  -Xverbosepath
It describes how paths and standard extensions were searched to find source and class files.




See also: Running code: In-depth

Comments

Popular Posts